<!doctype html>
<html lang="zh"><head>
<title>js-常用的js工具函数 - 糖羽仙</title>
<meta charset="UTF-8">
<meta name="keywords" content="blog ACG JavaScript VUE IT">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=5">

<link rel="shortcut icon" href="/images/head/head.jpg" type="image/jpeg" />
<meta name="description" content="整理一下前端开发中常用的工具方法，有了这些工具函数就可以高效的处理任务和信息了。">
<meta property="og:type" content="article">
<meta property="og:title" content="js-常用的js工具函数">
<meta property="og:url" content="https://www.tangyuxian.com/2021/04/08/%E5%89%8D%E7%AB%AF/JavaScript/js-%E5%B8%B8%E7%94%A8%E7%9A%84js%E5%B7%A5%E5%85%B7%E5%87%BD%E6%95%B0/index.html">
<meta property="og:site_name" content="糖羽仙">
<meta property="og:description" content="整理一下前端开发中常用的工具方法，有了这些工具函数就可以高效的处理任务和信息了。">
<meta property="og:locale" content="zh_CN">
<meta property="article:published_time" content="2021-04-08T07:17:56.000Z">
<meta property="article:modified_time" content="2022-08-20T10:06:06.030Z">
<meta property="article:author" content="tangyuxian">
<meta property="article:tag" content="工具">
<meta property="article:tag" content="JavaScript">
<meta name="twitter:card" content="summary">

<link rel="stylesheet" href="/lib/fancybox/fancybox.css">
<link rel="stylesheet" href="/lib/mdui_043tiny/mdui.css">


<link rel="stylesheet" href="/lib/iconfont/iconfont.css?v=1763992124159">

    <link rel="stylesheet" href="//at.alicdn.com/t/font_2421060_8z08qcz5sq3.css">

<link rel="stylesheet" href="/css/style.css?v=1763992124159">




    
        <link rel="stylesheet" href="/custom.css?v=1763992124159">
    
        <link rel="stylesheet" href="/themes/umaru/index.css?v=1763992124159">
    
        <link rel="stylesheet" href="/themes/asuka/index.css?v=1763992124159">
    



<script src="/lib/mdui_043tiny/mdui.js" async></script>
<script src="/lib/fancybox/fancybox.umd.js" async></script>
<script src="/lib/lax.min.js" async></script>


<script async src="/js/app.js?v=1763992124159"></script>

 

<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=G-1Z7TFL96ZH"></script>
<script>
  window.dataLayer = window.dataLayer || [];
  function gtag(){dataLayer.push(arguments);}
  gtag('js', new Date());

  gtag('config', 'G-1Z7TFL96ZH');
</script>


<link rel="stylesheet"  href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.8.0/styles/atom-one-dark.min.css">
<!-- hexo injector head_end start -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/hexo-shiki-plugin@latest/lib/codeblock.css">
<style>:root{--hl-color:#e1e4e8;--hl-bg:#24292e;--hltools-bg:#1f2428;--hltools-color:#c5c5c5;--hlnumber-bg:#24292e;--hlnumber-color:#444d56;--hlscrollbar-bg:#32383e;--hlexpand-bg:linear-gradient(180deg,rgba(36,41,46,0.1),rgba(36,41,46,0.9))}</style><!-- hexo injector head_end end --><meta name="generator" content="Hexo 7.3.0"></head><body class="nexmoe mdui-drawer-body-left"><div id="nexmoe-background"><div class="nexmoe-bg" style="background-image: url(/images/background/xiaomai.jpg)"></div><div class="nexmoe-character"></div><div class="mdui-appbar mdui-shadow-0"><div class="mdui-toolbar"><a class="mdui-btn mdui-btn-icon mdui-ripple" mdui-drawer="{target: &#039;#drawer&#039;, swipe: true}" title="menu"><i class="mdui-icon nexmoefont icon-menu"></i></a><div class="mdui-toolbar-spacer"></div><a class="mdui-btn mdui-btn-icon" href="/" title="tangyuxian"><img src="/images/head/head.jpg" alt="tangyuxian"></a></div></div></div><div id="nexmoe-header"><div class="nexmoe-drawer mdui-drawer" id="drawer">
    <div class="nexmoe-avatar mdui-ripple">
        <a href="/" title="tangyuxian">
            <img src="/images/head/head.jpg" alt="tangyuxian" alt="tangyuxian">
        </a>
    </div>
    <div class="nexmoe-count">
        <div class="nexmoe-count-item"><span>文章</span>84 <div class="item-radius"></div><div class="item-radius item-right"></div> </div>
        <div class="nexmoe-count-item"><span>标签</span>38<div class="item-radius"></div><div class="item-radius item-right"></div></div>
        <div class="nexmoe-count-item"><span>分类</span>5<div class="item-radius"></div><div class="item-radius item-right"></div></div>
    </div>
    <div class="nexmoe-list mdui-list" mdui-collapse="{accordion: true}">
        
        <a class="nexmoe-list-item mdui-list-item mdui-ripple false" href="/" title="回到首页">
            <i class="mdui-list-item-icon nexmoefont icon-meishi"></i>
            <div class="mdui-list-item-content">
                回到首页
            </div>
        </a>
        
        <a class="nexmoe-list-item mdui-list-item mdui-ripple false" href="/archives.html" title="文章归档">
            <i class="mdui-list-item-icon nexmoefont icon-hanbao1"></i>
            <div class="mdui-list-item-content">
                文章归档
            </div>
        </a>
        
        <a class="nexmoe-list-item mdui-list-item mdui-ripple false" href="/about.html" title="关于糖糖">
            <i class="mdui-list-item-icon nexmoefont icon-jiubei1"></i>
            <div class="mdui-list-item-content">
                关于糖糖
            </div>
        </a>
        
        <a class="nexmoe-list-item mdui-list-item mdui-ripple false" href="/friend.html" title="我的朋友">
            <i class="mdui-list-item-icon nexmoefont icon-cola"></i>
            <div class="mdui-list-item-content">
                我的朋友
            </div>
        </a>
        
    </div>
    
    
        
        <div class="nexmoe-widget-wrap">
    <div class="nexmoe-widget nexmoe-search">
         
            <form id="search_form" action_e="https://cn.bing.com/search?q=site:tangyuxian.com" onsubmit="return search();">
                <label><input id="search_value" name="q" type="search" placeholder="搜索"></label>
            </form>
         
    </div>
</div>




    
        
        <div class="nexmoe-widget-wrap">
	<div class="nexmoe-widget nexmoe-social">
		<a
			class="mdui-ripple"
			href="http://wpa.qq.com/msgrd?v=3&uin=2120252100&site=qq&menu=yes"
			target="_blank"
			mdui-tooltip="{content: 'QQ'}"
			style="
				color: rgb(64, 196, 255);
				background-color: rgba(64, 196, 255, .1);
			"
		>
			<i
				class="nexmoefont icon-QQ"
			></i> </a
		><a
			class="mdui-ripple"
			href="mailto:tangyuxian@vip.qq.com"
			target="_blank"
			mdui-tooltip="{content: 'mail'}"
			style="
				color: rgb(249,8,8);
				background-color: rgba(249,8,8,.1);
			"
		>
			<i
				class="nexmoefont icon-mail-fill"
			></i> </a
		><a
			class="mdui-ripple"
			href="https://blog.csdn.net/qq_40621378?type=blog"
			target="_blank"
			mdui-tooltip="{content: 'CSDN'}"
			style="
				color: rgb(199,29,35);
				background-color: rgba(199,29,35,.1);
			"
		>
			<i
				class="nexmoefont icon-csdn"
			></i> </a
		><a
			class="mdui-ripple"
			href="https://www.cnblogs.com/lovetangyuxian/"
			target="_blank"
			mdui-tooltip="{content: '博客园'}"
			style="
				color: rgb(66, 214, 29);
				background-color: rgba(66, 214, 29, .1);
			"
		>
			<i
				class="nexmoefont icon-bokeyuan"
			></i> </a
		><a
			class="mdui-ripple"
			href="https://github.com/tangyuxian/"
			target="_blank"
			mdui-tooltip="{content: 'GitHub'}"
			style="
				color: rgb(25, 23, 23);
				background-color: rgba(25, 23, 23, .15);
			"
		>
			<i
				class="nexmoefont icon-github"
			></i> </a
		><a
			class="mdui-ripple"
			href="https://gitee.com/tangyuxian"
			target="_blank"
			mdui-tooltip="{content: 'gitee'}"
			style="
				color: rgb(255, 255, 255);
				background-color: rgb(199,29,35);
			"
		>
			<i
				class="nexmoefont icon-mayun"
			></i> </a
		>
	</div>
</div>

    
        
        
  <div class="nexmoe-widget-wrap">
    <h3 class="nexmoe-widget-title">文章分类</h3>
    <div class="nexmoe-widget">

      <ul class="category-list">

        


        

        

        <li class="category-list-item">
          <a class="category-list-link" href="/categories/其它/">其它</a>
          <span class="category-list-count">2</span>
        </li>

        

        <li class="category-list-item">
          <a class="category-list-link" href="/categories/前端/">前端</a>
          <span class="category-list-count">62</span>
        </li>

        

        <li class="category-list-item">
          <a class="category-list-link" href="/categories/后端/">后端</a>
          <span class="category-list-count">8</span>
        </li>

        

        <li class="category-list-item">
          <a class="category-list-link" href="/categories/开发工具/">开发工具</a>
          <span class="category-list-count">11</span>
        </li>

        

        <li class="category-list-item">
          <a class="category-list-link" href="/categories/服务器端/">服务器端</a>
          <span class="category-list-count">1</span>
        </li>

        
      </ul>

    </div>
  </div>


    
        
        
  <div class="nexmoe-widget-wrap">
    <div id="randomtagcloud" class="nexmoe-widget tagcloud nexmoe-rainbow">
      <a href="/tags/JavaScript/" style="font-size: 15.56px;">JavaScript</a> <a href="/tags/Jetbrains/" style="font-size: 10px;">Jetbrains</a> <a href="/tags/TypeScript/" style="font-size: 10px;">TypeScript</a> <a href="/tags/UI%E5%BA%93/" style="font-size: 13.33px;">UI库</a> <a href="/tags/centos/" style="font-size: 10px;">centos</a> <a href="/tags/css/" style="font-size: 11.11px;">css</a> <a href="/tags/docker/" style="font-size: 10px;">docker</a> <a href="/tags/echarts/" style="font-size: 10px;">echarts</a> <a href="/tags/elementPlus/" style="font-size: 13.33px;">elementPlus</a> <a href="/tags/es6/" style="font-size: 14.44px;">es6</a> <a href="/tags/git/" style="font-size: 13.33px;">git</a> <a href="/tags/github/" style="font-size: 10px;">github</a> <a href="/tags/html/" style="font-size: 10px;">html</a> <a href="/tags/http/" style="font-size: 13.33px;">http</a> <a href="/tags/java/" style="font-size: 11.11px;">java</a> <a href="/tags/markerdown/" style="font-size: 11.11px;">markerdown</a> <a href="/tags/nginx/" style="font-size: 10px;">nginx</a> <a href="/tags/node/" style="font-size: 13.33px;">node</a> <a href="/tags/vite/" style="font-size: 10px;">vite</a> <a href="/tags/vue/" style="font-size: 18.89px;">vue</a> <a href="/tags/webpack/" style="font-size: 10px;">webpack</a> <a href="/tags/xuex/" style="font-size: 10px;">xuex</a> <a href="/tags/%E4%BA%8B%E4%BB%B6%E6%B5%81/" style="font-size: 10px;">事件流</a> <a href="/tags/%E4%BA%92%E8%81%94%E7%BD%91/" style="font-size: 10px;">互联网</a> <a href="/tags/%E5%8A%A0%E5%AF%86/" style="font-size: 12.22px;">加密</a> <a href="/tags/%E5%8E%9F%E5%88%9B/" style="font-size: 20px;">原创</a> <a href="/tags/%E5%B7%A5%E5%85%B7/" style="font-size: 13.33px;">工具</a> <a href="/tags/%E5%BE%AE%E4%BF%A1%E5%B0%8F%E7%A8%8B%E5%BA%8F/" style="font-size: 12.22px;">微信小程序</a> <a href="/tags/%E6%80%BB%E7%BB%93/" style="font-size: 13.33px;">总结</a> <a href="/tags/%E6%95%B0%E6%8D%AE%E7%BB%93%E6%9E%84/" style="font-size: 10px;">数据结构</a> <a href="/tags/%E6%9C%8D%E5%8A%A1%E5%99%A8/" style="font-size: 10px;">服务器</a> <a href="/tags/%E6%B5%8F%E8%A7%88%E5%99%A8/" style="font-size: 17.78px;">浏览器</a> <a href="/tags/%E7%AE%97%E6%B3%95/" style="font-size: 14.44px;">算法</a> <a href="/tags/%E7%BC%96%E8%A7%A3%E7%A0%81/" style="font-size: 10px;">编解码</a> <a href="/tags/%E7%BE%8E%E5%8C%96/" style="font-size: 12.22px;">美化</a> <a href="/tags/%E8%A7%86%E9%A2%91/" style="font-size: 11.11px;">视频</a> <a href="/tags/%E8%AE%B0%E5%BD%95/" style="font-size: 11.11px;">记录</a> <a href="/tags/%E8%BD%AC%E8%BD%BD/" style="font-size: 16.67px;">转载</a>
    </div>
    
      <script>
        var maxTagcloud = parseInt(17);
        var tags_length = parseInt(38);
        var tags_arr = [];
        for(var i = 0; i < tags_length; i++){
          tags_arr.push(i);
        }
        tags_arr.sort(function (l, r) {
          return Math.random() > 0.5 ? -1 : 1;
        });
        tags_arr = tags_arr.slice(0, maxTagcloud < tags_length ? tags_length - maxTagcloud : 0);
        for(var tag_i = 0; tag_i < tags_arr.length; tag_i++){
          document.getElementById("randomtagcloud").children[tags_arr[tag_i]].style.display = 'none';
        }
      </script>
    
  </div>

    
        
        
        
  <div class="nexmoe-widget-wrap">
    <h3 class="nexmoe-widget-title">文章归档</h3>
    <div class="nexmoe-widget">
      <ul class="archive-list"><li class="archive-list-item"><a class="archive-list-link" href="/archives/2025/">2025</a><span class="archive-list-count">5</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2023/">2023</a><span class="archive-list-count">2</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2022/">2022</a><span class="archive-list-count">23</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2021/">2021</a><span class="archive-list-count">54</span></li></ul>
    </div>
  </div>



    
        
        
  <div class="nexmoe-widget-wrap">
    <h3 class="nexmoe-widget-title">最新文章</h3>
    <div class="nexmoe-widget">
      <ul>
        
          <li>
            <a href="/2025/11/12/%E5%BC%80%E5%8F%91%E5%B7%A5%E5%85%B7/%E7%BE%8E%E5%8C%96/%E7%BE%8E%E5%8C%96-%E7%BD%91%E9%A1%B5%E4%B8%BB%E9%A2%98%E5%88%87%E6%8D%A2%E7%9A%84%E6%B8%90%E5%8F%98%E5%8A%A8%E7%94%BB/">美化-网页主题切换的渐变动画</a>
          </li>
        
          <li>
            <a href="/2025/09/29/%E5%89%8D%E7%AB%AF/css/css-%E8%A1%A8%E6%A0%BCtd%E4%B8%8B%E9%AB%98%E5%BA%A6%E4%B8%A2%E5%A4%B1%E8%A7%A3%E5%86%B3%E5%8A%9E%E6%B3%95/">css-表格td下高度丢失解决办法</a>
          </li>
        
          <li>
            <a href="/2025/09/23/%E5%89%8D%E7%AB%AF/vue/vue-%E5%B0%81%E8%A3%85%E5%87%BD%E6%95%B0%E5%BC%8F%E8%A7%A6%E5%8F%91%E5%8F%B3%E9%94%AE%E8%8F%9C%E5%8D%95/">vue-封装函数式触发右键菜单组件</a>
          </li>
        
          <li>
            <a href="/2025/06/04/%E5%89%8D%E7%AB%AF/UI%E5%BA%93/UI%E5%BA%93-ElTooltip%E5%8F%AA%E5%9C%A8%E6%96%87%E5%AD%97%E8%B6%85%E5%87%BA%E8%8C%83%E5%9B%B4%E6%97%B6%E6%98%BE%E7%A4%BA%E7%9A%84%E8%A7%86%E7%BA%BF%E6%96%B9%E5%BC%8F/">UI库-ElTooltip只在文字超出范围时显示的视线方式</a>
          </li>
        
          <li>
            <a href="/2025/05/29/%E5%89%8D%E7%AB%AF/UI%E5%BA%93/UI%E5%BA%93-%E5%B0%81%E8%A3%85PageTable%E6%80%BB%E8%A7%88/">UI库-封装PageTable总览</a>
          </li>
        
      </ul>
    </div>
  </div>

    
        
        <div class="nexmoe-widget-wrap">
    <div class="nexmoe-widget nexmoe-link">
		<ul>
        
            <li>
                <a href="https://tangyuxian.com/" target="_blank" >
                    <img src="https://cdn.tangyuxian.com/PicGoImages/202304272004917.jpg" alt="糖糖第一可爱"></img>
                    <p style="color: var(--color-primary)">糖糖第一可爱</p>
                </a>
            </li>
        
		</ul>
    </div>
</div>
<style>
.nexmoe-widget-wrap .nexmoe-link ul li a {
    text-align : center;
}
.nexmoe-widget-wrap .nexmoe-link ul li a img {
    max-width : 100%;
}
.nexmoe-widget-wrap .nexmoe-link ul li a p {
    margin: 10px 0;
}
</style>

    
   
    <div class="nexmoe-copyright">
        &copy; 2025 tangyuxian
        Powered by <a href="http://hexo.io/" target="_blank">Hexo</a>
        & <a href="https://github.com/tangyuxian/hexo-theme-tangyuxian" target="_blank">Tangyuxian</a>
        <br><a target="_blank" href="https://beian.miit.gov.cn/">辽ICP备2021002341号</a>
<div style="font-size: 12px">
   <script async src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>
   本站总访问量  <a id="busuanzi_value_site_pv"></a> 次<br />
   本站访客数<a id="busuanzi_value_site_uv"></a>人次
</div>

    </div>
</div><!-- .nexmoe-drawer --></div><div id="nexmoe-content"><div class="nexmoe-primary"><div class="nexmoe-post">
  <article>
    
        <div class="nexmoe-post-cover">
            <img src="/images/post/editor.jpg" alt="js-常用的js工具函数" loading="lazy">
            <h1>js-常用的js工具函数</h1>
        </div>
        
    
    <div class="nexmoe-post-meta">
    <div class="nexmoe-rainbow">
        <a class="nexmoefont icon-calendar-fill">2021年04月08日</a>
        
            <a class="nexmoefont icon-appstore-fill -link" href="/categories/%E5%89%8D%E7%AB%AF/">前端</a>
        
        
    </div>
    
    
    
    
    
</div>

    <p>整理一下前端开发中常用的工具方法，有了这些工具函数就可以高效的处理任务和信息了。</p>
<span id="more"></span>
<h4 id="1-邮箱"><a href="#1-邮箱" class="headerlink" title="1.邮箱"></a>1.邮箱</h4><figure class="shiki javascript"><div class='codeblock'><div class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></div><div class="code"><pre class="shiki github-dark"><code><span class="line"><span style="color: #F97583">export</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">const</span><span style="color: #E1E4E8"> </span><span style="color: #B392F0">isEmail</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> (</span><span style="color: #FFAB70">s</span><span style="color: #E1E4E8">) </span><span style="color: #F97583">=&gt;</span><span style="color: #E1E4E8"> {</span></span>
<span class="line"><span style="color: #E1E4E8">    </span><span style="color: #F97583">return</span><span style="color: #9ECBFF"> /</span><span style="color: #F97583">^</span><span style="color: #DBEDFF">(</span><span style="color: #79B8FF">[a-zA-Z0-9_-]</span><span style="color: #DBEDFF">)</span><span style="color: #F97583">+</span><span style="color: #DBEDFF">@(</span><span style="color: #79B8FF">[a-zA-Z0-9_-]</span><span style="color: #DBEDFF">)</span><span style="color: #F97583">+</span><span style="color: #DBEDFF">((</span><span style="color: #79B8FF">.[a-zA-Z0-9_-]</span><span style="color: #F97583">{2,3}</span><span style="color: #DBEDFF">)</span><span style="color: #F97583">{1,2}</span><span style="color: #DBEDFF">)</span><span style="color: #F97583">$</span><span style="color: #9ECBFF">/</span><span style="color: #E1E4E8">.</span><span style="color: #B392F0">test</span><span style="color: #E1E4E8">(s)</span></span>
<span class="line"><span style="color: #E1E4E8">}</span></span></code></pre></div></div></figure>

<h4 id="2-手机号码"><a href="#2-手机号码" class="headerlink" title="2.手机号码"></a>2.手机号码</h4><figure class="shiki javascript"><div class='codeblock'><div class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></div><div class="code"><pre class="shiki github-dark"><code><span class="line"><span style="color: #F97583">export</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">const</span><span style="color: #E1E4E8"> </span><span style="color: #B392F0">isMobile</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> (</span><span style="color: #FFAB70">s</span><span style="color: #E1E4E8">) </span><span style="color: #F97583">=&gt;</span><span style="color: #E1E4E8"> {</span></span>
<span class="line"><span style="color: #E1E4E8">    </span><span style="color: #F97583">return</span><span style="color: #DBEDFF"> </span><span style="color: #9ECBFF">/</span><span style="color: #F97583">^</span><span style="color: #DBEDFF">1</span><span style="color: #79B8FF">[0-9]</span><span style="color: #F97583">{10}$</span><span style="color: #9ECBFF">/</span><span style="color: #E1E4E8">.</span><span style="color: #B392F0">test</span><span style="color: #E1E4E8">(s)</span></span>
<span class="line"><span style="color: #E1E4E8">}</span></span></code></pre></div></div></figure>

<h4 id="3-电话号码"><a href="#3-电话号码" class="headerlink" title="3.电话号码"></a>3.电话号码</h4><figure class="shiki javascript"><div class='codeblock'><div class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></div><div class="code"><pre class="shiki github-dark"><code><span class="line"><span style="color: #F97583">export</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">const</span><span style="color: #E1E4E8"> </span><span style="color: #B392F0">isPhone</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> (</span><span style="color: #FFAB70">s</span><span style="color: #E1E4E8">) </span><span style="color: #F97583">=&gt;</span><span style="color: #E1E4E8"> {</span></span>
<span class="line"><span style="color: #E1E4E8">    </span><span style="color: #F97583">return</span><span style="color: #DBEDFF"> </span><span style="color: #9ECBFF">/</span><span style="color: #F97583">^</span><span style="color: #DBEDFF">(</span><span style="color: #79B8FF">[0-9]</span><span style="color: #F97583">{3,4}</span><span style="color: #DBEDFF">-)</span><span style="color: #F97583">?</span><span style="color: #79B8FF">[0-9]</span><span style="color: #F97583">{7,8}$</span><span style="color: #9ECBFF">/</span><span style="color: #E1E4E8">.</span><span style="color: #B392F0">test</span><span style="color: #E1E4E8">(s)</span></span>
<span class="line"><span style="color: #E1E4E8">}</span></span></code></pre></div></div></figure>

<h4 id="4-是否为url地址"><a href="#4-是否为url地址" class="headerlink" title="4.是否为url地址"></a>4.是否为url地址</h4><figure class="shiki javascript"><div class='codeblock'><div class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></div><div class="code"><pre class="shiki github-dark"><code><span class="line"><span style="color: #F97583">export</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">const</span><span style="color: #E1E4E8"> </span><span style="color: #B392F0">isURL</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> (</span><span style="color: #FFAB70">s</span><span style="color: #E1E4E8">) </span><span style="color: #F97583">=&gt;</span><span style="color: #E1E4E8"> {</span></span>
<span class="line"><span style="color: #E1E4E8">    </span><span style="color: #F97583">return</span><span style="color: #DBEDFF"> </span><span style="color: #9ECBFF">/</span><span style="color: #F97583">^</span><span style="color: #DBEDFF">http</span><span style="color: #79B8FF">[s]</span><span style="color: #F97583">?</span><span style="color: #DBEDFF">:</span><span style="color: #85E89D; font-weight: bold">\/\/</span><span style="color: #79B8FF">.</span><span style="color: #F97583">*</span><span style="color: #9ECBFF">/</span><span style="color: #E1E4E8">.</span><span style="color: #B392F0">test</span><span style="color: #E1E4E8">(s)</span></span>
<span class="line"><span style="color: #E1E4E8">}</span></span></code></pre></div></div></figure>

<h4 id="5-是否字符串"><a href="#5-是否字符串" class="headerlink" title="5.是否字符串"></a>5.是否字符串</h4><figure class="shiki javascript"><div class='codeblock'><div class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></div><div class="code"><pre class="shiki github-dark"><code><span class="line"><span style="color: #F97583">export</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">const</span><span style="color: #E1E4E8"> </span><span style="color: #B392F0">isString</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> (</span><span style="color: #FFAB70">o</span><span style="color: #E1E4E8">) </span><span style="color: #F97583">=&gt;</span><span style="color: #E1E4E8"> {</span></span>
<span class="line"><span style="color: #E1E4E8">    </span><span style="color: #F97583">return</span><span style="color: #E1E4E8"> </span><span style="color: #79B8FF">Object</span><span style="color: #E1E4E8">.</span><span style="color: #79B8FF">prototype</span><span style="color: #E1E4E8">.toString.</span><span style="color: #B392F0">call</span><span style="color: #E1E4E8">(o).</span><span style="color: #B392F0">slice</span><span style="color: #E1E4E8">(</span><span style="color: #79B8FF">8</span><span style="color: #E1E4E8">, </span><span style="color: #F97583">-</span><span style="color: #79B8FF">1</span><span style="color: #E1E4E8">) </span><span style="color: #F97583">===</span><span style="color: #E1E4E8"> </span><span style="color: #9ECBFF">&#39;String&#39;</span></span>
<span class="line"><span style="color: #E1E4E8">}</span></span></code></pre></div></div></figure>

<h4 id="6-是否数字"><a href="#6-是否数字" class="headerlink" title="6.是否数字"></a>6.是否数字</h4><figure class="shiki javascript"><div class='codeblock'><div class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></div><div class="code"><pre class="shiki github-dark"><code><span class="line"><span style="color: #F97583">export</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">const</span><span style="color: #E1E4E8"> </span><span style="color: #B392F0">isNumber</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> (</span><span style="color: #FFAB70">o</span><span style="color: #E1E4E8">) </span><span style="color: #F97583">=&gt;</span><span style="color: #E1E4E8"> {</span></span>
<span class="line"><span style="color: #E1E4E8">    </span><span style="color: #F97583">return</span><span style="color: #E1E4E8"> </span><span style="color: #79B8FF">Object</span><span style="color: #E1E4E8">.</span><span style="color: #79B8FF">prototype</span><span style="color: #E1E4E8">.toString.</span><span style="color: #B392F0">call</span><span style="color: #E1E4E8">(o).</span><span style="color: #B392F0">slice</span><span style="color: #E1E4E8">(</span><span style="color: #79B8FF">8</span><span style="color: #E1E4E8">, </span><span style="color: #F97583">-</span><span style="color: #79B8FF">1</span><span style="color: #E1E4E8">) </span><span style="color: #F97583">===</span><span style="color: #E1E4E8"> </span><span style="color: #9ECBFF">&#39;Number&#39;</span></span>
<span class="line"><span style="color: #E1E4E8">}</span></span></code></pre></div></div></figure>

<h4 id="7-是否为boolean"><a href="#7-是否为boolean" class="headerlink" title="7.是否为boolean"></a>7.是否为boolean</h4><figure class="shiki javascript"><div class='codeblock'><div class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></div><div class="code"><pre class="shiki github-dark"><code><span class="line"><span style="color: #F97583">export</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">const</span><span style="color: #E1E4E8"> </span><span style="color: #B392F0">isBoolean</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> (</span><span style="color: #FFAB70">o</span><span style="color: #E1E4E8">) </span><span style="color: #F97583">=&gt;</span><span style="color: #E1E4E8"> {</span></span>
<span class="line"><span style="color: #E1E4E8">    </span><span style="color: #F97583">return</span><span style="color: #E1E4E8"> </span><span style="color: #79B8FF">Object</span><span style="color: #E1E4E8">.</span><span style="color: #79B8FF">prototype</span><span style="color: #E1E4E8">.toString.</span><span style="color: #B392F0">call</span><span style="color: #E1E4E8">(o).</span><span style="color: #B392F0">slice</span><span style="color: #E1E4E8">(</span><span style="color: #79B8FF">8</span><span style="color: #E1E4E8">, </span><span style="color: #F97583">-</span><span style="color: #79B8FF">1</span><span style="color: #E1E4E8">) </span><span style="color: #F97583">===</span><span style="color: #E1E4E8"> </span><span style="color: #9ECBFF">&#39;Boolean&#39;</span></span>
<span class="line"><span style="color: #E1E4E8">}</span></span></code></pre></div></div></figure>

<h4 id="8-是否为函数"><a href="#8-是否为函数" class="headerlink" title="8.是否为函数"></a>8.是否为函数</h4><figure class="shiki javascript"><div class='codeblock'><div class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></div><div class="code"><pre class="shiki github-dark"><code><span class="line"><span style="color: #F97583">export</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">const</span><span style="color: #E1E4E8"> </span><span style="color: #B392F0">isFunction</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> (</span><span style="color: #FFAB70">o</span><span style="color: #E1E4E8">) </span><span style="color: #F97583">=&gt;</span><span style="color: #E1E4E8"> {</span></span>
<span class="line"><span style="color: #E1E4E8">    </span><span style="color: #F97583">return</span><span style="color: #E1E4E8"> </span><span style="color: #79B8FF">Object</span><span style="color: #E1E4E8">.</span><span style="color: #79B8FF">prototype</span><span style="color: #E1E4E8">.toString.</span><span style="color: #B392F0">call</span><span style="color: #E1E4E8">(o).</span><span style="color: #B392F0">slice</span><span style="color: #E1E4E8">(</span><span style="color: #79B8FF">8</span><span style="color: #E1E4E8">, </span><span style="color: #F97583">-</span><span style="color: #79B8FF">1</span><span style="color: #E1E4E8">) </span><span style="color: #F97583">===</span><span style="color: #E1E4E8"> </span><span style="color: #9ECBFF">&#39;Function&#39;</span></span>
<span class="line"><span style="color: #E1E4E8">}</span></span></code></pre></div></div></figure>

<h4 id="9-是否为null"><a href="#9-是否为null" class="headerlink" title="9.是否为null"></a>9.是否为null</h4><figure class="shiki javascript"><div class='codeblock'><div class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></div><div class="code"><pre class="shiki github-dark"><code><span class="line"><span style="color: #F97583">export</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">const</span><span style="color: #E1E4E8"> </span><span style="color: #B392F0">isNull</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> (</span><span style="color: #FFAB70">o</span><span style="color: #E1E4E8">) </span><span style="color: #F97583">=&gt;</span><span style="color: #E1E4E8"> {</span></span>
<span class="line"><span style="color: #E1E4E8">    </span><span style="color: #F97583">return</span><span style="color: #E1E4E8"> </span><span style="color: #79B8FF">Object</span><span style="color: #E1E4E8">.</span><span style="color: #79B8FF">prototype</span><span style="color: #E1E4E8">.toString.</span><span style="color: #B392F0">call</span><span style="color: #E1E4E8">(o).</span><span style="color: #B392F0">slice</span><span style="color: #E1E4E8">(</span><span style="color: #79B8FF">8</span><span style="color: #E1E4E8">, </span><span style="color: #F97583">-</span><span style="color: #79B8FF">1</span><span style="color: #E1E4E8">) </span><span style="color: #F97583">===</span><span style="color: #E1E4E8"> </span><span style="color: #9ECBFF">&#39;Null&#39;</span></span>
<span class="line"><span style="color: #E1E4E8">}</span></span></code></pre></div></div></figure>

<h4 id="10-是否为undefined"><a href="#10-是否为undefined" class="headerlink" title="10.是否为undefined"></a>10.是否为undefined</h4><figure class="shiki javascript"><div class='codeblock'><div class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></div><div class="code"><pre class="shiki github-dark"><code><span class="line"><span style="color: #F97583">export</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">const</span><span style="color: #E1E4E8"> </span><span style="color: #B392F0">isUndefined</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> (</span><span style="color: #FFAB70">o</span><span style="color: #E1E4E8">) </span><span style="color: #F97583">=&gt;</span><span style="color: #E1E4E8"> {</span></span>
<span class="line"><span style="color: #E1E4E8">    </span><span style="color: #F97583">return</span><span style="color: #E1E4E8"> </span><span style="color: #79B8FF">Object</span><span style="color: #E1E4E8">.</span><span style="color: #79B8FF">prototype</span><span style="color: #E1E4E8">.toString.</span><span style="color: #B392F0">call</span><span style="color: #E1E4E8">(o).</span><span style="color: #B392F0">slice</span><span style="color: #E1E4E8">(</span><span style="color: #79B8FF">8</span><span style="color: #E1E4E8">, </span><span style="color: #F97583">-</span><span style="color: #79B8FF">1</span><span style="color: #E1E4E8">) </span><span style="color: #F97583">===</span><span style="color: #E1E4E8"> </span><span style="color: #9ECBFF">&#39;Undefined&#39;</span></span>
<span class="line"><span style="color: #E1E4E8">}</span></span></code></pre></div></div></figure>

<h4 id="11-是否为对象"><a href="#11-是否为对象" class="headerlink" title="11.是否为对象"></a>11.是否为对象</h4><figure class="shiki javascript"><div class='codeblock'><div class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></div><div class="code"><pre class="shiki github-dark"><code><span class="line"><span style="color: #F97583">export</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">const</span><span style="color: #E1E4E8"> </span><span style="color: #B392F0">isObj</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> (</span><span style="color: #FFAB70">o</span><span style="color: #E1E4E8">) </span><span style="color: #F97583">=&gt;</span><span style="color: #E1E4E8"> {</span></span>
<span class="line"><span style="color: #E1E4E8">    </span><span style="color: #F97583">return</span><span style="color: #E1E4E8"> </span><span style="color: #79B8FF">Object</span><span style="color: #E1E4E8">.</span><span style="color: #79B8FF">prototype</span><span style="color: #E1E4E8">.toString.</span><span style="color: #B392F0">call</span><span style="color: #E1E4E8">(o).</span><span style="color: #B392F0">slice</span><span style="color: #E1E4E8">(</span><span style="color: #79B8FF">8</span><span style="color: #E1E4E8">, </span><span style="color: #F97583">-</span><span style="color: #79B8FF">1</span><span style="color: #E1E4E8">) </span><span style="color: #F97583">===</span><span style="color: #E1E4E8"> </span><span style="color: #9ECBFF">&#39;Object&#39;</span></span>
<span class="line"><span style="color: #E1E4E8">}</span></span></code></pre></div></div></figure>

<h4 id="12-是否为数组"><a href="#12-是否为数组" class="headerlink" title="12.是否为数组"></a>12.是否为数组</h4><figure class="shiki javascript"><div class='codeblock'><div class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></div><div class="code"><pre class="shiki github-dark"><code><span class="line"><span style="color: #F97583">export</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">const</span><span style="color: #E1E4E8"> </span><span style="color: #B392F0">isArray</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> (</span><span style="color: #FFAB70">o</span><span style="color: #E1E4E8">) </span><span style="color: #F97583">=&gt;</span><span style="color: #E1E4E8"> {</span></span>
<span class="line"><span style="color: #E1E4E8">    </span><span style="color: #F97583">return</span><span style="color: #E1E4E8"> </span><span style="color: #79B8FF">Object</span><span style="color: #E1E4E8">.</span><span style="color: #79B8FF">prototype</span><span style="color: #E1E4E8">.toString.</span><span style="color: #B392F0">call</span><span style="color: #E1E4E8">(o).</span><span style="color: #B392F0">slice</span><span style="color: #E1E4E8">(</span><span style="color: #79B8FF">8</span><span style="color: #E1E4E8">, </span><span style="color: #F97583">-</span><span style="color: #79B8FF">1</span><span style="color: #E1E4E8">) </span><span style="color: #F97583">===</span><span style="color: #E1E4E8"> </span><span style="color: #9ECBFF">&#39;Array&#39;</span></span>
<span class="line"><span style="color: #E1E4E8">}</span></span></code></pre></div></div></figure>

<h4 id="13-是否为时间"><a href="#13-是否为时间" class="headerlink" title="13.是否为时间"></a>13.是否为时间</h4><figure class="shiki javascript"><div class='codeblock'><div class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></div><div class="code"><pre class="shiki github-dark"><code><span class="line"><span style="color: #F97583">export</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">const</span><span style="color: #E1E4E8"> </span><span style="color: #B392F0">isDate</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> (</span><span style="color: #FFAB70">o</span><span style="color: #E1E4E8">) </span><span style="color: #F97583">=&gt;</span><span style="color: #E1E4E8"> {</span></span>
<span class="line"><span style="color: #E1E4E8">    </span><span style="color: #F97583">return</span><span style="color: #E1E4E8"> </span><span style="color: #79B8FF">Object</span><span style="color: #E1E4E8">.</span><span style="color: #79B8FF">prototype</span><span style="color: #E1E4E8">.toString.</span><span style="color: #B392F0">call</span><span style="color: #E1E4E8">(o).</span><span style="color: #B392F0">slice</span><span style="color: #E1E4E8">(</span><span style="color: #79B8FF">8</span><span style="color: #E1E4E8">, </span><span style="color: #F97583">-</span><span style="color: #79B8FF">1</span><span style="color: #E1E4E8">) </span><span style="color: #F97583">===</span><span style="color: #E1E4E8"> </span><span style="color: #9ECBFF">&#39;Date&#39;</span></span>
<span class="line"><span style="color: #E1E4E8">}</span></span></code></pre></div></div></figure>

<h4 id="14-是否为正则"><a href="#14-是否为正则" class="headerlink" title="14.是否为正则"></a>14.是否为正则</h4><figure class="shiki javascript"><div class='codeblock'><div class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></div><div class="code"><pre class="shiki github-dark"><code><span class="line"><span style="color: #F97583">export</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">const</span><span style="color: #E1E4E8"> </span><span style="color: #B392F0">isRegExp</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> (</span><span style="color: #FFAB70">o</span><span style="color: #E1E4E8">) </span><span style="color: #F97583">=&gt;</span><span style="color: #E1E4E8"> {</span></span>
<span class="line"><span style="color: #E1E4E8">    </span><span style="color: #F97583">return</span><span style="color: #E1E4E8"> </span><span style="color: #79B8FF">Object</span><span style="color: #E1E4E8">.</span><span style="color: #79B8FF">prototype</span><span style="color: #E1E4E8">.toString.</span><span style="color: #B392F0">call</span><span style="color: #E1E4E8">(o).</span><span style="color: #B392F0">slice</span><span style="color: #E1E4E8">(</span><span style="color: #79B8FF">8</span><span style="color: #E1E4E8">, </span><span style="color: #F97583">-</span><span style="color: #79B8FF">1</span><span style="color: #E1E4E8">) </span><span style="color: #F97583">===</span><span style="color: #E1E4E8"> </span><span style="color: #9ECBFF">&#39;RegExp&#39;</span></span>
<span class="line"><span style="color: #E1E4E8">}</span></span></code></pre></div></div></figure>

<h4 id="15-是否为错误对象"><a href="#15-是否为错误对象" class="headerlink" title="15.是否为错误对象"></a>15.是否为错误对象</h4><figure class="shiki javascript"><div class='codeblock'><div class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></div><div class="code"><pre class="shiki github-dark"><code><span class="line"><span style="color: #F97583">export</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">const</span><span style="color: #E1E4E8"> </span><span style="color: #B392F0">isError</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> (</span><span style="color: #FFAB70">o</span><span style="color: #E1E4E8">) </span><span style="color: #F97583">=&gt;</span><span style="color: #E1E4E8"> {</span></span>
<span class="line"><span style="color: #E1E4E8">    </span><span style="color: #F97583">return</span><span style="color: #E1E4E8"> </span><span style="color: #79B8FF">Object</span><span style="color: #E1E4E8">.</span><span style="color: #79B8FF">prototype</span><span style="color: #E1E4E8">.toString.</span><span style="color: #B392F0">call</span><span style="color: #E1E4E8">(o).</span><span style="color: #B392F0">slice</span><span style="color: #E1E4E8">(</span><span style="color: #79B8FF">8</span><span style="color: #E1E4E8">, </span><span style="color: #F97583">-</span><span style="color: #79B8FF">1</span><span style="color: #E1E4E8">) </span><span style="color: #F97583">===</span><span style="color: #E1E4E8"> </span><span style="color: #9ECBFF">&#39;Error&#39;</span></span>
<span class="line"><span style="color: #E1E4E8">}</span></span></code></pre></div></div></figure>

<h4 id="16-是否为Symbol函数"><a href="#16-是否为Symbol函数" class="headerlink" title="16.是否为Symbol函数"></a>16.是否为Symbol函数</h4><figure class="shiki javascript"><div class='codeblock'><div class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></div><div class="code"><pre class="shiki github-dark"><code><span class="line"><span style="color: #F97583">export</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">const</span><span style="color: #E1E4E8"> </span><span style="color: #B392F0">isSymbol</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> (</span><span style="color: #FFAB70">o</span><span style="color: #E1E4E8">) </span><span style="color: #F97583">=&gt;</span><span style="color: #E1E4E8"> {</span></span>
<span class="line"><span style="color: #E1E4E8">    </span><span style="color: #F97583">return</span><span style="color: #E1E4E8"> </span><span style="color: #79B8FF">Object</span><span style="color: #E1E4E8">.</span><span style="color: #79B8FF">prototype</span><span style="color: #E1E4E8">.toString.</span><span style="color: #B392F0">call</span><span style="color: #E1E4E8">(o).</span><span style="color: #B392F0">slice</span><span style="color: #E1E4E8">(</span><span style="color: #79B8FF">8</span><span style="color: #E1E4E8">, </span><span style="color: #F97583">-</span><span style="color: #79B8FF">1</span><span style="color: #E1E4E8">) </span><span style="color: #F97583">===</span><span style="color: #E1E4E8"> </span><span style="color: #9ECBFF">&#39;Symbol&#39;</span></span>
<span class="line"><span style="color: #E1E4E8">}</span></span></code></pre></div></div></figure>

<h4 id="17-是否为Promise对象"><a href="#17-是否为Promise对象" class="headerlink" title="17.是否为Promise对象"></a>17.是否为Promise对象</h4><figure class="shiki javascript"><div class='codeblock'><div class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></div><div class="code"><pre class="shiki github-dark"><code><span class="line"><span style="color: #F97583">export</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">const</span><span style="color: #E1E4E8"> </span><span style="color: #B392F0">isPromise</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> (</span><span style="color: #FFAB70">o</span><span style="color: #E1E4E8">) </span><span style="color: #F97583">=&gt;</span><span style="color: #E1E4E8"> {</span></span>
<span class="line"><span style="color: #E1E4E8">    </span><span style="color: #F97583">return</span><span style="color: #E1E4E8"> </span><span style="color: #79B8FF">Object</span><span style="color: #E1E4E8">.</span><span style="color: #79B8FF">prototype</span><span style="color: #E1E4E8">.toString.</span><span style="color: #B392F0">call</span><span style="color: #E1E4E8">(o).</span><span style="color: #B392F0">slice</span><span style="color: #E1E4E8">(</span><span style="color: #79B8FF">8</span><span style="color: #E1E4E8">, </span><span style="color: #F97583">-</span><span style="color: #79B8FF">1</span><span style="color: #E1E4E8">) </span><span style="color: #F97583">===</span><span style="color: #E1E4E8"> </span><span style="color: #9ECBFF">&#39;Promise&#39;</span></span>
<span class="line"><span style="color: #E1E4E8">}</span></span></code></pre></div></div></figure>

<h4 id="18-是否为Set对象"><a href="#18-是否为Set对象" class="headerlink" title="18.是否为Set对象"></a>18.是否为Set对象</h4><figure class="shiki javascript"><div class='codeblock'><div class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></div><div class="code"><pre class="shiki github-dark"><code><span class="line"><span style="color: #F97583">export</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">const</span><span style="color: #E1E4E8"> </span><span style="color: #B392F0">isSet</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> (</span><span style="color: #FFAB70">o</span><span style="color: #E1E4E8">) </span><span style="color: #F97583">=&gt;</span><span style="color: #E1E4E8"> {    </span></span>
<span class="line"><span style="color: #E1E4E8">    </span><span style="color: #F97583">return</span><span style="color: #E1E4E8"> </span><span style="color: #79B8FF">Object</span><span style="color: #E1E4E8">.</span><span style="color: #79B8FF">prototype</span><span style="color: #E1E4E8">.toString.</span><span style="color: #B392F0">call</span><span style="color: #E1E4E8">(o).</span><span style="color: #B392F0">slice</span><span style="color: #E1E4E8">(</span><span style="color: #79B8FF">8</span><span style="color: #E1E4E8">, </span><span style="color: #F97583">-</span><span style="color: #79B8FF">1</span><span style="color: #E1E4E8">) </span><span style="color: #F97583">===</span><span style="color: #E1E4E8"> </span><span style="color: #9ECBFF">&#39;Set&#39;</span><span style="color: #E1E4E8"> </span></span>
<span class="line"><span style="color: #E1E4E8">}</span></span></code></pre></div></div></figure>

<h4 id="19-是否是微信浏览器"><a href="#19-是否是微信浏览器" class="headerlink" title="19.是否是微信浏览器"></a>19.是否是微信浏览器</h4><figure class="shiki javascript"><div class='codeblock'><div class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></div><div class="code"><pre class="shiki github-dark"><code><span class="line"><span style="color: #F97583">export</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">const</span><span style="color: #E1E4E8"> </span><span style="color: #B392F0">isWeiXin</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> () </span><span style="color: #F97583">=&gt;</span><span style="color: #E1E4E8"> {</span></span>
<span class="line"><span style="color: #E1E4E8">    </span><span style="color: #F97583">return</span><span style="color: #E1E4E8"> (navigator.userAgent.</span><span style="color: #B392F0">toLowerCase</span><span style="color: #E1E4E8">()).</span><span style="color: #B392F0">match</span><span style="color: #E1E4E8">(</span><span style="color: #9ECBFF">/</span><span style="color: #DBEDFF">microMessenger</span><span style="color: #9ECBFF">/</span><span style="color: #F97583">i</span><span style="color: #E1E4E8">) </span><span style="color: #F97583">==</span><span style="color: #E1E4E8"> </span><span style="color: #9ECBFF">&#39;micromessenger&#39;</span></span>
<span class="line"><span style="color: #E1E4E8">}</span></span></code></pre></div></div></figure>

<h4 id="20-是否为移动端"><a href="#20-是否为移动端" class="headerlink" title="20.是否为移动端"></a>20.是否为移动端</h4><figure class="shiki javascript"><div class='codeblock'><div class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></div><div class="code"><pre class="shiki github-dark"><code><span class="line"><span style="color: #F97583">export</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">const</span><span style="color: #E1E4E8"> </span><span style="color: #B392F0">isDeviceMobile</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> () </span><span style="color: #F97583">=&gt;</span><span style="color: #E1E4E8"> {</span></span>
<span class="line"><span style="color: #E1E4E8">    </span><span style="color: #F97583">return</span><span style="color: #DBEDFF"> </span><span style="color: #9ECBFF">/</span><span style="color: #DBEDFF">android</span><span style="color: #F97583">|</span><span style="color: #DBEDFF">webos</span><span style="color: #F97583">|</span><span style="color: #DBEDFF">iphone</span><span style="color: #F97583">|</span><span style="color: #DBEDFF">ipod</span><span style="color: #F97583">|</span><span style="color: #DBEDFF">balckberry</span><span style="color: #9ECBFF">/</span><span style="color: #F97583">i</span><span style="color: #E1E4E8">.</span><span style="color: #B392F0">test</span><span style="color: #E1E4E8">(ua)</span></span>
<span class="line"><span style="color: #E1E4E8">}</span></span></code></pre></div></div></figure>

<h4 id="21-是否是QQ浏览器"><a href="#21-是否是QQ浏览器" class="headerlink" title="21.是否是QQ浏览器"></a>21.是否是QQ浏览器</h4><figure class="shiki javascript"><div class='codeblock'><div class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></div><div class="code"><pre class="shiki github-dark"><code><span class="line"><span style="color: #F97583">export</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">const</span><span style="color: #E1E4E8"> </span><span style="color: #B392F0">isQQBrowser</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> () </span><span style="color: #F97583">=&gt;</span><span style="color: #E1E4E8"> {</span></span>
<span class="line"><span style="color: #E1E4E8">    </span><span style="color: #F97583">return</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">!!</span><span style="color: #E1E4E8">ua.</span><span style="color: #B392F0">match</span><span style="color: #E1E4E8">(</span><span style="color: #9ECBFF">/</span><span style="color: #DBEDFF">mqqbrowser</span><span style="color: #F97583">|</span><span style="color: #DBEDFF">qzone</span><span style="color: #F97583">|</span><span style="color: #DBEDFF">qqbrowser</span><span style="color: #F97583">|</span><span style="color: #DBEDFF">qbwebviewtype</span><span style="color: #9ECBFF">/</span><span style="color: #F97583">i</span><span style="color: #E1E4E8">)</span></span>
<span class="line"><span style="color: #E1E4E8">}</span></span></code></pre></div></div></figure>

<h4 id="22-是否为ios"><a href="#22-是否为ios" class="headerlink" title="22.是否为ios"></a>22.是否为ios</h4><figure class="shiki javascript"><div class='codeblock'><div class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></div><div class="code"><pre class="shiki github-dark"><code><span class="line"><span style="color: #F97583">export</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">const</span><span style="color: #E1E4E8"> </span><span style="color: #B392F0">isIos</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> () </span><span style="color: #F97583">=&gt;</span><span style="color: #E1E4E8"> {</span></span>
<span class="line"><span style="color: #E1E4E8">  </span><span style="color: #F97583">var</span><span style="color: #E1E4E8"> u </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> navigator.userAgent;</span></span>
<span class="line"><span style="color: #E1E4E8">  </span><span style="color: #F97583">if</span><span style="color: #E1E4E8"> (u.</span><span style="color: #B392F0">indexOf</span><span style="color: #E1E4E8">(</span><span style="color: #9ECBFF">&#39;Android&#39;</span><span style="color: #E1E4E8">) </span><span style="color: #F97583">&gt;</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">-</span><span style="color: #79B8FF">1</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">||</span><span style="color: #E1E4E8"> u.</span><span style="color: #B392F0">indexOf</span><span style="color: #E1E4E8">(</span><span style="color: #9ECBFF">&#39;Linux&#39;</span><span style="color: #E1E4E8">) </span><span style="color: #F97583">&gt;</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">-</span><span style="color: #79B8FF">1</span><span style="color: #E1E4E8">) {  </span></span>
<span class="line"><span style="color: #E1E4E8">    </span><span style="color: #6A737D">// 安卓手机</span></span>
<span class="line"><span style="color: #E1E4E8">    </span><span style="color: #F97583">return</span><span style="color: #E1E4E8"> </span><span style="color: #79B8FF">false</span></span>
<span class="line"><span style="color: #E1E4E8">  } </span><span style="color: #F97583">else</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">if</span><span style="color: #E1E4E8"> (u.</span><span style="color: #B392F0">indexOf</span><span style="color: #E1E4E8">(</span><span style="color: #9ECBFF">&#39;iPhone&#39;</span><span style="color: #E1E4E8">) </span><span style="color: #F97583">&gt;</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">-</span><span style="color: #79B8FF">1</span><span style="color: #E1E4E8">) {</span></span>
<span class="line"><span style="color: #E1E4E8">    </span><span style="color: #6A737D">// 苹果手机</span></span>
<span class="line"><span style="color: #E1E4E8">    </span><span style="color: #F97583">return</span><span style="color: #E1E4E8"> </span><span style="color: #79B8FF">true</span></span>
<span class="line"><span style="color: #E1E4E8">  } </span><span style="color: #F97583">else</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">if</span><span style="color: #E1E4E8"> (u.</span><span style="color: #B392F0">indexOf</span><span style="color: #E1E4E8">(</span><span style="color: #9ECBFF">&#39;iPad&#39;</span><span style="color: #E1E4E8">) </span><span style="color: #F97583">&gt;</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">-</span><span style="color: #79B8FF">1</span><span style="color: #E1E4E8">) { </span></span>
<span class="line"><span style="color: #E1E4E8">    </span><span style="color: #6A737D">// iPad</span></span>
<span class="line"><span style="color: #E1E4E8">    </span><span style="color: #F97583">return</span><span style="color: #E1E4E8"> </span><span style="color: #79B8FF">false</span></span>
<span class="line"><span style="color: #E1E4E8">  } </span><span style="color: #F97583">else</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">if</span><span style="color: #E1E4E8"> (u.</span><span style="color: #B392F0">indexOf</span><span style="color: #E1E4E8">(</span><span style="color: #9ECBFF">&#39;Windows Phone&#39;</span><span style="color: #E1E4E8">) </span><span style="color: #F97583">&gt;</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">-</span><span style="color: #79B8FF">1</span><span style="color: #E1E4E8">) {</span></span>
<span class="line"><span style="color: #E1E4E8">    </span><span style="color: #6A737D">//winphone手机</span></span>
<span class="line"><span style="color: #E1E4E8">    </span><span style="color: #F97583">return</span><span style="color: #E1E4E8"> </span><span style="color: #79B8FF">false</span></span>
<span class="line"><span style="color: #E1E4E8">  } </span><span style="color: #F97583">else</span><span style="color: #E1E4E8"> {</span></span>
<span class="line"><span style="color: #E1E4E8">    </span><span style="color: #F97583">return</span><span style="color: #E1E4E8"> </span><span style="color: #79B8FF">false</span></span>
<span class="line"><span style="color: #E1E4E8">  }</span></span>
<span class="line"><span style="color: #E1E4E8">}</span></span></code></pre></div></div></figure>

<h4 id="23-是否为PC端"><a href="#23-是否为PC端" class="headerlink" title="23.是否为PC端"></a>23.是否为PC端</h4><figure class="shiki javascript"><div class='codeblock'><div class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></div><div class="code"><pre class="shiki github-dark"><code><span class="line"><span style="color: #F97583">export</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">const</span><span style="color: #E1E4E8"> </span><span style="color: #B392F0">isPC</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> () </span><span style="color: #F97583">=&gt;</span><span style="color: #E1E4E8"> {</span></span>
<span class="line"><span style="color: #E1E4E8">  </span><span style="color: #F97583">var</span><span style="color: #E1E4E8"> userAgentInfo </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> navigator.userAgent;</span></span>
<span class="line"><span style="color: #E1E4E8">  </span><span style="color: #F97583">var</span><span style="color: #E1E4E8"> Agents </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> [</span><span style="color: #9ECBFF">&quot;Android&quot;</span><span style="color: #E1E4E8">, </span><span style="color: #9ECBFF">&quot;iPhone&quot;</span><span style="color: #E1E4E8">,</span></span>
<span class="line"><span style="color: #E1E4E8">    </span><span style="color: #9ECBFF">&quot;SymbianOS&quot;</span><span style="color: #E1E4E8">, </span><span style="color: #9ECBFF">&quot;Windows Phone&quot;</span><span style="color: #E1E4E8">,</span></span>
<span class="line"><span style="color: #E1E4E8">    </span><span style="color: #9ECBFF">&quot;iPad&quot;</span><span style="color: #E1E4E8">, </span><span style="color: #9ECBFF">&quot;iPod&quot;</span><span style="color: #E1E4E8">];</span></span>
<span class="line"><span style="color: #E1E4E8">  </span><span style="color: #F97583">var</span><span style="color: #E1E4E8"> flag </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> </span><span style="color: #79B8FF">true</span><span style="color: #E1E4E8">;</span></span>
<span class="line"><span style="color: #E1E4E8">  </span><span style="color: #F97583">for</span><span style="color: #E1E4E8"> (</span><span style="color: #F97583">var</span><span style="color: #E1E4E8"> v </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> </span><span style="color: #79B8FF">0</span><span style="color: #E1E4E8">; v </span><span style="color: #F97583">&lt;</span><span style="color: #E1E4E8"> Agents.</span><span style="color: #79B8FF">length</span><span style="color: #E1E4E8">; v</span><span style="color: #F97583">++</span><span style="color: #E1E4E8">) {</span></span>
<span class="line"><span style="color: #E1E4E8">    </span><span style="color: #F97583">if</span><span style="color: #E1E4E8"> (userAgentInfo.</span><span style="color: #B392F0">indexOf</span><span style="color: #E1E4E8">(Agents[v]) </span><span style="color: #F97583">&gt;</span><span style="color: #E1E4E8"> </span><span style="color: #79B8FF">0</span><span style="color: #E1E4E8">) {</span></span>
<span class="line"><span style="color: #E1E4E8">      flag </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> </span><span style="color: #79B8FF">false</span><span style="color: #E1E4E8">;</span></span>
<span class="line"><span style="color: #E1E4E8">      </span><span style="color: #F97583">break</span><span style="color: #E1E4E8">;</span></span>
<span class="line"><span style="color: #E1E4E8">    }</span></span>
<span class="line"><span style="color: #E1E4E8">  }</span></span>
<span class="line"><span style="color: #E1E4E8">  </span><span style="color: #F97583">return</span><span style="color: #E1E4E8"> flag;</span></span>
<span class="line"><span style="color: #E1E4E8">}</span></span></code></pre></div></div></figure>

<h4 id="24-去除html标签"><a href="#24-去除html标签" class="headerlink" title="24.去除html标签"></a>24.去除html标签</h4><figure class="shiki javascript"><div class='codeblock'><div class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></div><div class="code"><pre class="shiki github-dark"><code><span class="line"><span style="color: #F97583">export</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">const</span><span style="color: #E1E4E8"> </span><span style="color: #B392F0">removeHtmltag</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> (</span><span style="color: #FFAB70">str</span><span style="color: #E1E4E8">) </span><span style="color: #F97583">=&gt;</span><span style="color: #E1E4E8"> {</span></span>
<span class="line"><span style="color: #E1E4E8">    </span><span style="color: #F97583">return</span><span style="color: #E1E4E8"> str.</span><span style="color: #B392F0">replace</span><span style="color: #E1E4E8">(</span><span style="color: #9ECBFF">/</span><span style="color: #DBEDFF">&lt;</span><span style="color: #79B8FF">[</span><span style="color: #F97583">^</span><span style="color: #79B8FF">&gt;]</span><span style="color: #F97583">+</span><span style="color: #DBEDFF">&gt;</span><span style="color: #9ECBFF">/</span><span style="color: #F97583">g</span><span style="color: #E1E4E8">, </span><span style="color: #9ECBFF">&#39;&#39;</span><span style="color: #E1E4E8">)</span></span>
<span class="line"><span style="color: #E1E4E8">}</span></span></code></pre></div></div></figure>

<h4 id="25-获取url参数"><a href="#25-获取url参数" class="headerlink" title="25.获取url参数"></a>25.获取url参数</h4><figure class="shiki javascript"><div class='codeblock'><div class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></div><div class="code"><pre class="shiki github-dark"><code><span class="line"><span style="color: #F97583">export</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">const</span><span style="color: #E1E4E8"> </span><span style="color: #B392F0">getQueryString</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> (</span><span style="color: #FFAB70">name</span><span style="color: #E1E4E8">) </span><span style="color: #F97583">=&gt;</span><span style="color: #E1E4E8"> {</span></span>
<span class="line"><span style="color: #E1E4E8">  </span><span style="color: #F97583">const</span><span style="color: #E1E4E8"> </span><span style="color: #79B8FF">reg</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">new</span><span style="color: #E1E4E8"> </span><span style="color: #B392F0">RegExp</span><span style="color: #E1E4E8">(</span><span style="color: #9ECBFF">&#39;(^|&amp;)&#39;</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">+</span><span style="color: #E1E4E8"> name </span><span style="color: #F97583">+</span><span style="color: #E1E4E8"> </span><span style="color: #9ECBFF">&#39;=([^&amp;]*)(&amp;|$)&#39;</span><span style="color: #E1E4E8">, </span><span style="color: #9ECBFF">&#39;i&#39;</span><span style="color: #E1E4E8">);</span></span>
<span class="line"><span style="color: #E1E4E8">  </span><span style="color: #F97583">const</span><span style="color: #E1E4E8"> </span><span style="color: #79B8FF">search</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> window.location.search.</span><span style="color: #B392F0">split</span><span style="color: #E1E4E8">(</span><span style="color: #9ECBFF">&#39;?&#39;</span><span style="color: #E1E4E8">)[</span><span style="color: #79B8FF">1</span><span style="color: #E1E4E8">] </span><span style="color: #F97583">||</span><span style="color: #E1E4E8"> </span><span style="color: #9ECBFF">&#39;&#39;</span><span style="color: #E1E4E8">;</span></span>
<span class="line"><span style="color: #E1E4E8">  </span><span style="color: #F97583">const</span><span style="color: #E1E4E8"> </span><span style="color: #79B8FF">r</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> search.</span><span style="color: #B392F0">match</span><span style="color: #E1E4E8">(reg) </span><span style="color: #F97583">||</span><span style="color: #E1E4E8"> [];</span></span>
<span class="line"><span style="color: #E1E4E8">  </span><span style="color: #F97583">return</span><span style="color: #E1E4E8"> r[</span><span style="color: #79B8FF">2</span><span style="color: #E1E4E8">];</span></span>
<span class="line"><span style="color: #E1E4E8">}</span></span></code></pre></div></div></figure>

<h4 id="26-动态引入js"><a href="#26-动态引入js" class="headerlink" title="26.动态引入js"></a>26.动态引入js</h4><figure class="shiki javascript"><div class='codeblock'><div class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></div><div class="code"><pre class="shiki github-dark"><code><span class="line"><span style="color: #F97583">export</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">const</span><span style="color: #E1E4E8"> </span><span style="color: #B392F0">injectScript</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> (</span><span style="color: #FFAB70">src</span><span style="color: #E1E4E8">) </span><span style="color: #F97583">=&gt;</span><span style="color: #E1E4E8"> {</span></span>
<span class="line"><span style="color: #E1E4E8">  </span><span style="color: #F97583">const</span><span style="color: #E1E4E8"> </span><span style="color: #79B8FF">s</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> document.</span><span style="color: #B392F0">createElement</span><span style="color: #E1E4E8">(</span><span style="color: #9ECBFF">&#39;script&#39;</span><span style="color: #E1E4E8">);</span></span>
<span class="line"><span style="color: #E1E4E8">  s.type </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> </span><span style="color: #9ECBFF">&#39;text/javascript&#39;</span><span style="color: #E1E4E8">;</span></span>
<span class="line"><span style="color: #E1E4E8">  s.async </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> </span><span style="color: #79B8FF">true</span><span style="color: #E1E4E8">;</span></span>
<span class="line"><span style="color: #E1E4E8">  s.src </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> src;</span></span>
<span class="line"><span style="color: #E1E4E8">  </span><span style="color: #F97583">const</span><span style="color: #E1E4E8"> </span><span style="color: #79B8FF">t</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> document.</span><span style="color: #B392F0">getElementsByTagName</span><span style="color: #E1E4E8">(</span><span style="color: #9ECBFF">&#39;script&#39;</span><span style="color: #E1E4E8">)[</span><span style="color: #79B8FF">0</span><span style="color: #E1E4E8">];</span></span>
<span class="line"><span style="color: #E1E4E8">  t.parentNode.</span><span style="color: #B392F0">insertBefore</span><span style="color: #E1E4E8">(s, t);</span></span>
<span class="line"><span style="color: #E1E4E8">}</span></span></code></pre></div></div></figure>

<h4 id="27-根据url地址下载"><a href="#27-根据url地址下载" class="headerlink" title="27.根据url地址下载"></a>27.根据url地址下载</h4><figure class="shiki javascript"><div class='codeblock'><div class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br></pre></div><div class="code"><pre class="shiki github-dark"><code><span class="line"><span style="color: #F97583">export</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">const</span><span style="color: #E1E4E8"> </span><span style="color: #B392F0">download</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> (</span><span style="color: #FFAB70">url</span><span style="color: #E1E4E8">) </span><span style="color: #F97583">=&gt;</span><span style="color: #E1E4E8"> {</span></span>
<span class="line"><span style="color: #E1E4E8">  </span><span style="color: #F97583">var</span><span style="color: #E1E4E8"> isChrome </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> navigator.userAgent.</span><span style="color: #B392F0">toLowerCase</span><span style="color: #E1E4E8">().</span><span style="color: #B392F0">indexOf</span><span style="color: #E1E4E8">(</span><span style="color: #9ECBFF">&#39;chrome&#39;</span><span style="color: #E1E4E8">) </span><span style="color: #F97583">&gt;</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">-</span><span style="color: #79B8FF">1</span><span style="color: #E1E4E8">;</span></span>
<span class="line"><span style="color: #E1E4E8">  </span><span style="color: #F97583">var</span><span style="color: #E1E4E8"> isSafari </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> navigator.userAgent.</span><span style="color: #B392F0">toLowerCase</span><span style="color: #E1E4E8">().</span><span style="color: #B392F0">indexOf</span><span style="color: #E1E4E8">(</span><span style="color: #9ECBFF">&#39;safari&#39;</span><span style="color: #E1E4E8">) </span><span style="color: #F97583">&gt;</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">-</span><span style="color: #79B8FF">1</span><span style="color: #E1E4E8">;</span></span>
<span class="line"><span style="color: #E1E4E8">  </span><span style="color: #F97583">if</span><span style="color: #E1E4E8"> (isChrome </span><span style="color: #F97583">||</span><span style="color: #E1E4E8"> isSafari) {</span></span>
<span class="line"><span style="color: #E1E4E8">    </span><span style="color: #F97583">var</span><span style="color: #E1E4E8"> link </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> document.</span><span style="color: #B392F0">createElement</span><span style="color: #E1E4E8">(</span><span style="color: #9ECBFF">&#39;a&#39;</span><span style="color: #E1E4E8">);</span></span>
<span class="line"><span style="color: #E1E4E8">    link.href </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> url;</span></span>
<span class="line"><span style="color: #E1E4E8">    </span><span style="color: #F97583">if</span><span style="color: #E1E4E8"> (link.download </span><span style="color: #F97583">!==</span><span style="color: #E1E4E8"> </span><span style="color: #79B8FF">undefined</span><span style="color: #E1E4E8">) {</span></span>
<span class="line"><span style="color: #E1E4E8">      </span><span style="color: #F97583">var</span><span style="color: #E1E4E8"> fileName </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> url.</span><span style="color: #B392F0">substring</span><span style="color: #E1E4E8">(url.</span><span style="color: #B392F0">lastIndexOf</span><span style="color: #E1E4E8">(</span><span style="color: #9ECBFF">&#39;/&#39;</span><span style="color: #E1E4E8">) </span><span style="color: #F97583">+</span><span style="color: #E1E4E8"> </span><span style="color: #79B8FF">1</span><span style="color: #E1E4E8">, url.</span><span style="color: #79B8FF">length</span><span style="color: #E1E4E8">);</span></span>
<span class="line"><span style="color: #E1E4E8">      link.download </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> fileName;</span></span>
<span class="line"><span style="color: #E1E4E8">    }</span></span>
<span class="line"><span style="color: #E1E4E8">    </span><span style="color: #F97583">if</span><span style="color: #E1E4E8"> (document.createEvent) {</span></span>
<span class="line"><span style="color: #E1E4E8">      </span><span style="color: #F97583">var</span><span style="color: #E1E4E8"> e </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> document.</span><span style="color: #B392F0">createEvent</span><span style="color: #E1E4E8">(</span><span style="color: #9ECBFF">&#39;MouseEvents&#39;</span><span style="color: #E1E4E8">);</span></span>
<span class="line"><span style="color: #E1E4E8">      e.</span><span style="color: #B392F0">initEvent</span><span style="color: #E1E4E8">(</span><span style="color: #9ECBFF">&#39;click&#39;</span><span style="color: #E1E4E8">, </span><span style="color: #79B8FF">true</span><span style="color: #E1E4E8">, </span><span style="color: #79B8FF">true</span><span style="color: #E1E4E8">);</span></span>
<span class="line"><span style="color: #E1E4E8">      link.</span><span style="color: #B392F0">dispatchEvent</span><span style="color: #E1E4E8">(e);</span></span>
<span class="line"><span style="color: #E1E4E8">      </span><span style="color: #F97583">return</span><span style="color: #E1E4E8"> </span><span style="color: #79B8FF">true</span><span style="color: #E1E4E8">;</span></span>
<span class="line"><span style="color: #E1E4E8">    }</span></span>
<span class="line"><span style="color: #E1E4E8">  }</span></span>
<span class="line"><span style="color: #E1E4E8">  </span><span style="color: #F97583">if</span><span style="color: #E1E4E8"> (url.</span><span style="color: #B392F0">indexOf</span><span style="color: #E1E4E8">(</span><span style="color: #9ECBFF">&#39;?&#39;</span><span style="color: #E1E4E8">) </span><span style="color: #F97583">===</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">-</span><span style="color: #79B8FF">1</span><span style="color: #E1E4E8">) {</span></span>
<span class="line"><span style="color: #E1E4E8">    url </span><span style="color: #F97583">+=</span><span style="color: #E1E4E8"> </span><span style="color: #9ECBFF">&#39;?download&#39;</span><span style="color: #E1E4E8">;</span></span>
<span class="line"><span style="color: #E1E4E8">  }</span></span>
<span class="line"><span style="color: #E1E4E8">  window.</span><span style="color: #B392F0">open</span><span style="color: #E1E4E8">(url, </span><span style="color: #9ECBFF">&#39;_self&#39;</span><span style="color: #E1E4E8">);</span></span>
<span class="line"><span style="color: #E1E4E8">  </span><span style="color: #F97583">return</span><span style="color: #E1E4E8"> </span><span style="color: #79B8FF">true</span><span style="color: #E1E4E8">;</span></span>
<span class="line"><span style="color: #E1E4E8">}</span></span></code></pre></div></div></figure>

<h4 id="28-el是否包含某个class"><a href="#28-el是否包含某个class" class="headerlink" title="28.el是否包含某个class"></a>28.el是否包含某个class</h4><figure class="shiki javascript"><div class='codeblock'><div class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></div><div class="code"><pre class="shiki github-dark"><code><span class="line"><span style="color: #F97583">export</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">const</span><span style="color: #E1E4E8"> </span><span style="color: #B392F0">hasClass</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> (</span><span style="color: #FFAB70">el</span><span style="color: #E1E4E8">, </span><span style="color: #FFAB70">className</span><span style="color: #E1E4E8">) </span><span style="color: #F97583">=&gt;</span><span style="color: #E1E4E8"> {</span></span>
<span class="line"><span style="color: #E1E4E8">  </span><span style="color: #F97583">let</span><span style="color: #E1E4E8"> reg </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">new</span><span style="color: #E1E4E8"> </span><span style="color: #B392F0">RegExp</span><span style="color: #E1E4E8">(</span><span style="color: #9ECBFF">&#39;(^|</span><span style="color: #79B8FF">\\</span><span style="color: #9ECBFF">s)&#39;</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">+</span><span style="color: #E1E4E8"> className </span><span style="color: #F97583">+</span><span style="color: #E1E4E8"> </span><span style="color: #9ECBFF">&#39;(</span><span style="color: #79B8FF">\\</span><span style="color: #9ECBFF">s|$)&#39;</span><span style="color: #E1E4E8">)</span></span>
<span class="line"><span style="color: #E1E4E8">  </span><span style="color: #F97583">return</span><span style="color: #E1E4E8"> reg.</span><span style="color: #B392F0">test</span><span style="color: #E1E4E8">(el.className)</span></span>
<span class="line"><span style="color: #E1E4E8">}</span></span></code></pre></div></div></figure>

<h4 id="29-el添加某个class"><a href="#29-el添加某个class" class="headerlink" title="29.el添加某个class"></a>29.el添加某个class</h4><figure class="shiki javascript"><div class='codeblock'><div class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></div><div class="code"><pre class="shiki github-dark"><code><span class="line"><span style="color: #F97583">export</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">const</span><span style="color: #E1E4E8"> </span><span style="color: #B392F0">addClass</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> (</span><span style="color: #FFAB70">el</span><span style="color: #E1E4E8">, </span><span style="color: #FFAB70">className</span><span style="color: #E1E4E8">) </span><span style="color: #F97583">=&gt;</span><span style="color: #E1E4E8"> {</span></span>
<span class="line"><span style="color: #E1E4E8">  </span><span style="color: #F97583">if</span><span style="color: #E1E4E8"> (</span><span style="color: #B392F0">hasClass</span><span style="color: #E1E4E8">(el, className)) {</span></span>
<span class="line"><span style="color: #E1E4E8">    </span><span style="color: #F97583">return</span></span>
<span class="line"><span style="color: #E1E4E8">  }</span></span>
<span class="line"><span style="color: #E1E4E8">  </span><span style="color: #F97583">let</span><span style="color: #E1E4E8"> newClass </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> el.className.</span><span style="color: #B392F0">split</span><span style="color: #E1E4E8">(</span><span style="color: #9ECBFF">&#39; &#39;</span><span style="color: #E1E4E8">)</span></span>
<span class="line"><span style="color: #E1E4E8">  newClass.</span><span style="color: #B392F0">push</span><span style="color: #E1E4E8">(className)</span></span>
<span class="line"><span style="color: #E1E4E8">  el.className </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> newClass.</span><span style="color: #B392F0">join</span><span style="color: #E1E4E8">(</span><span style="color: #9ECBFF">&#39; &#39;</span><span style="color: #E1E4E8">)</span></span>
<span class="line"><span style="color: #E1E4E8">}</span></span></code></pre></div></div></figure>

<h4 id="30-el去除某个class"><a href="#30-el去除某个class" class="headerlink" title="30.el去除某个class"></a>30.el去除某个class</h4><figure class="shiki javascript"><div class='codeblock'><div class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></div><div class="code"><pre class="shiki github-dark"><code><span class="line"><span style="color: #F97583">export</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">const</span><span style="color: #E1E4E8"> </span><span style="color: #B392F0">removeClass</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> (</span><span style="color: #FFAB70">el</span><span style="color: #E1E4E8">, </span><span style="color: #FFAB70">className</span><span style="color: #E1E4E8">) </span><span style="color: #F97583">=&gt;</span><span style="color: #E1E4E8"> {</span></span>
<span class="line"><span style="color: #E1E4E8">  </span><span style="color: #F97583">if</span><span style="color: #E1E4E8"> (</span><span style="color: #F97583">!</span><span style="color: #B392F0">hasClass</span><span style="color: #E1E4E8">(el, className)) {</span></span>
<span class="line"><span style="color: #E1E4E8">    </span><span style="color: #F97583">return</span></span>
<span class="line"><span style="color: #E1E4E8">  }</span></span>
<span class="line"><span style="color: #E1E4E8">  </span><span style="color: #F97583">let</span><span style="color: #E1E4E8"> reg </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">new</span><span style="color: #E1E4E8"> </span><span style="color: #B392F0">RegExp</span><span style="color: #E1E4E8">(</span><span style="color: #9ECBFF">&#39;(^|</span><span style="color: #79B8FF">\\</span><span style="color: #9ECBFF">s)&#39;</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">+</span><span style="color: #E1E4E8"> className </span><span style="color: #F97583">+</span><span style="color: #E1E4E8"> </span><span style="color: #9ECBFF">&#39;(</span><span style="color: #79B8FF">\\</span><span style="color: #9ECBFF">s|$)&#39;</span><span style="color: #E1E4E8">, </span><span style="color: #9ECBFF">&#39;g&#39;</span><span style="color: #E1E4E8">)</span></span>
<span class="line"><span style="color: #E1E4E8">  el.className </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> el.className.</span><span style="color: #B392F0">replace</span><span style="color: #E1E4E8">(reg, </span><span style="color: #9ECBFF">&#39; &#39;</span><span style="color: #E1E4E8">)</span></span>
<span class="line"><span style="color: #E1E4E8">}</span></span></code></pre></div></div></figure>

<h4 id="31-获取滚动的坐标"><a href="#31-获取滚动的坐标" class="headerlink" title="31.获取滚动的坐标"></a>31.获取滚动的坐标</h4><figure class="shiki javascript"><div class='codeblock'><div class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></div><div class="code"><pre class="shiki github-dark"><code><span class="line"><span style="color: #F97583">export</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">const</span><span style="color: #E1E4E8"> </span><span style="color: #B392F0">getScrollPosition</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> (</span><span style="color: #FFAB70">el</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> window) </span><span style="color: #F97583">=&gt;</span><span style="color: #E1E4E8"> ({</span></span>
<span class="line"><span style="color: #E1E4E8">  x: el.pageXOffset </span><span style="color: #F97583">!==</span><span style="color: #E1E4E8"> </span><span style="color: #79B8FF">undefined</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">?</span><span style="color: #E1E4E8"> el.pageXOffset </span><span style="color: #F97583">:</span><span style="color: #E1E4E8"> el.scrollLeft,</span></span>
<span class="line"><span style="color: #E1E4E8">  y: el.pageYOffset </span><span style="color: #F97583">!==</span><span style="color: #E1E4E8"> </span><span style="color: #79B8FF">undefined</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">?</span><span style="color: #E1E4E8"> el.pageYOffset </span><span style="color: #F97583">:</span><span style="color: #E1E4E8"> el.scrollTop</span></span>
<span class="line"><span style="color: #E1E4E8">});</span></span></code></pre></div></div></figure>

<h4 id="32-滚动到顶部"><a href="#32-滚动到顶部" class="headerlink" title="32.滚动到顶部"></a>32.滚动到顶部</h4><figure class="shiki javascript"><div class='codeblock'><div class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></div><div class="code"><pre class="shiki github-dark"><code><span class="line"><span style="color: #F97583">export</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">const</span><span style="color: #E1E4E8"> </span><span style="color: #B392F0">scrollToTop</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> () </span><span style="color: #F97583">=&gt;</span><span style="color: #E1E4E8"> {</span></span>
<span class="line"><span style="color: #E1E4E8">  </span><span style="color: #F97583">const</span><span style="color: #E1E4E8"> </span><span style="color: #79B8FF">c</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> document.documentElement.scrollTop </span><span style="color: #F97583">||</span><span style="color: #E1E4E8"> document.body.scrollTop;</span></span>
<span class="line"><span style="color: #E1E4E8">  </span><span style="color: #F97583">if</span><span style="color: #E1E4E8"> (c </span><span style="color: #F97583">&gt;</span><span style="color: #E1E4E8"> </span><span style="color: #79B8FF">0</span><span style="color: #E1E4E8">) {</span></span>
<span class="line"><span style="color: #E1E4E8">    window.</span><span style="color: #B392F0">requestAnimationFrame</span><span style="color: #E1E4E8">(scrollToTop);</span></span>
<span class="line"><span style="color: #E1E4E8">    window.</span><span style="color: #B392F0">scrollTo</span><span style="color: #E1E4E8">(</span><span style="color: #79B8FF">0</span><span style="color: #E1E4E8">, c </span><span style="color: #F97583">-</span><span style="color: #E1E4E8"> c </span><span style="color: #F97583">/</span><span style="color: #E1E4E8"> </span><span style="color: #79B8FF">8</span><span style="color: #E1E4E8">);</span></span>
<span class="line"><span style="color: #E1E4E8">  }</span></span>
<span class="line"><span style="color: #E1E4E8">}</span></span></code></pre></div></div></figure>

<h4 id="33-el是否在视口范围内"><a href="#33-el是否在视口范围内" class="headerlink" title="33.el是否在视口范围内"></a>33.el是否在视口范围内</h4><figure class="shiki javascript"><div class='codeblock'><div class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></div><div class="code"><pre class="shiki github-dark"><code><span class="line"><span style="color: #F97583">export</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">const</span><span style="color: #E1E4E8"> </span><span style="color: #B392F0">elementIsVisibleInViewport</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> (</span><span style="color: #FFAB70">el</span><span style="color: #E1E4E8">, </span><span style="color: #FFAB70">partiallyVisible</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> </span><span style="color: #79B8FF">false</span><span style="color: #E1E4E8">) </span><span style="color: #F97583">=&gt;</span><span style="color: #E1E4E8"> {</span></span>
<span class="line"><span style="color: #E1E4E8">  </span><span style="color: #F97583">const</span><span style="color: #E1E4E8"> { </span><span style="color: #79B8FF">top</span><span style="color: #E1E4E8">, </span><span style="color: #79B8FF">left</span><span style="color: #E1E4E8">, </span><span style="color: #79B8FF">bottom</span><span style="color: #E1E4E8">, </span><span style="color: #79B8FF">right</span><span style="color: #E1E4E8"> } </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> el.</span><span style="color: #B392F0">getBoundingClientRect</span><span style="color: #E1E4E8">();</span></span>
<span class="line"><span style="color: #E1E4E8">  </span><span style="color: #F97583">const</span><span style="color: #E1E4E8"> { </span><span style="color: #79B8FF">innerHeight</span><span style="color: #E1E4E8">, </span><span style="color: #79B8FF">innerWidth</span><span style="color: #E1E4E8"> } </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> window;</span></span>
<span class="line"><span style="color: #E1E4E8">  </span><span style="color: #F97583">return</span><span style="color: #E1E4E8"> partiallyVisible</span></span>
<span class="line"><span style="color: #E1E4E8">    </span><span style="color: #F97583">?</span><span style="color: #E1E4E8"> ((top </span><span style="color: #F97583">&gt;</span><span style="color: #E1E4E8"> </span><span style="color: #79B8FF">0</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">&amp;&amp;</span><span style="color: #E1E4E8"> top </span><span style="color: #F97583">&lt;</span><span style="color: #E1E4E8"> innerHeight) </span><span style="color: #F97583">||</span><span style="color: #E1E4E8"> (bottom </span><span style="color: #F97583">&gt;</span><span style="color: #E1E4E8"> </span><span style="color: #79B8FF">0</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">&amp;&amp;</span><span style="color: #E1E4E8"> bottom </span><span style="color: #F97583">&lt;</span><span style="color: #E1E4E8"> innerHeight)) </span><span style="color: #F97583">&amp;&amp;</span></span>
<span class="line"><span style="color: #E1E4E8">    ((left </span><span style="color: #F97583">&gt;</span><span style="color: #E1E4E8"> </span><span style="color: #79B8FF">0</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">&amp;&amp;</span><span style="color: #E1E4E8"> left </span><span style="color: #F97583">&lt;</span><span style="color: #E1E4E8"> innerWidth) </span><span style="color: #F97583">||</span><span style="color: #E1E4E8"> (right </span><span style="color: #F97583">&gt;</span><span style="color: #E1E4E8"> </span><span style="color: #79B8FF">0</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">&amp;&amp;</span><span style="color: #E1E4E8"> right </span><span style="color: #F97583">&lt;</span><span style="color: #E1E4E8"> innerWidth))</span></span>
<span class="line"><span style="color: #E1E4E8">    </span><span style="color: #F97583">:</span><span style="color: #E1E4E8"> top </span><span style="color: #F97583">&gt;=</span><span style="color: #E1E4E8"> </span><span style="color: #79B8FF">0</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">&amp;&amp;</span><span style="color: #E1E4E8"> left </span><span style="color: #F97583">&gt;=</span><span style="color: #E1E4E8"> </span><span style="color: #79B8FF">0</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">&amp;&amp;</span><span style="color: #E1E4E8"> bottom </span><span style="color: #F97583">&lt;=</span><span style="color: #E1E4E8"> innerHeight </span><span style="color: #F97583">&amp;&amp;</span><span style="color: #E1E4E8"> right </span><span style="color: #F97583">&lt;=</span><span style="color: #E1E4E8"> innerWidth;</span></span>
<span class="line"><span style="color: #E1E4E8">}</span></span></code></pre></div></div></figure>

<h4 id="34-洗牌算法随机"><a href="#34-洗牌算法随机" class="headerlink" title="34.洗牌算法随机"></a>34.洗牌算法随机</h4><figure class="shiki javascript"><div class='codeblock'><div class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></div><div class="code"><pre class="shiki github-dark"><code><span class="line"><span style="color: #F97583">export</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">const</span><span style="color: #E1E4E8"> </span><span style="color: #B392F0">shuffle</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> (</span><span style="color: #FFAB70">arr</span><span style="color: #E1E4E8">) </span><span style="color: #F97583">=&gt;</span><span style="color: #E1E4E8"> {</span></span>
<span class="line"><span style="color: #E1E4E8">  </span><span style="color: #F97583">var</span><span style="color: #E1E4E8"> result </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> [],</span></span>
<span class="line"><span style="color: #E1E4E8">    random;</span></span>
<span class="line"><span style="color: #E1E4E8">  </span><span style="color: #F97583">while</span><span style="color: #E1E4E8"> (arr.</span><span style="color: #79B8FF">length</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">&gt;</span><span style="color: #E1E4E8"> </span><span style="color: #79B8FF">0</span><span style="color: #E1E4E8">) {</span></span>
<span class="line"><span style="color: #E1E4E8">    random </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> Math.</span><span style="color: #B392F0">floor</span><span style="color: #E1E4E8">(Math.</span><span style="color: #B392F0">random</span><span style="color: #E1E4E8">() </span><span style="color: #F97583">*</span><span style="color: #E1E4E8"> arr.</span><span style="color: #79B8FF">length</span><span style="color: #E1E4E8">);</span></span>
<span class="line"><span style="color: #E1E4E8">    result.</span><span style="color: #B392F0">push</span><span style="color: #E1E4E8">(arr[random])</span></span>
<span class="line"><span style="color: #E1E4E8">    arr.</span><span style="color: #B392F0">splice</span><span style="color: #E1E4E8">(random, </span><span style="color: #79B8FF">1</span><span style="color: #E1E4E8">)</span></span>
<span class="line"><span style="color: #E1E4E8">  }</span></span>
<span class="line"><span style="color: #E1E4E8">  </span><span style="color: #F97583">return</span><span style="color: #E1E4E8"> result;</span></span>
<span class="line"><span style="color: #E1E4E8">}</span></span></code></pre></div></div></figure>

<h4 id="35-劫持粘贴板"><a href="#35-劫持粘贴板" class="headerlink" title="35.劫持粘贴板"></a>35.劫持粘贴板</h4><figure class="shiki javascript"><div class='codeblock'><div class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></div><div class="code"><pre class="shiki github-dark"><code><span class="line"><span style="color: #F97583">export</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">const</span><span style="color: #E1E4E8"> </span><span style="color: #B392F0">copyTextToClipboard</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> (</span><span style="color: #FFAB70">value</span><span style="color: #E1E4E8">) </span><span style="color: #F97583">=&gt;</span><span style="color: #E1E4E8"> {</span></span>
<span class="line"><span style="color: #E1E4E8">  </span><span style="color: #F97583">var</span><span style="color: #E1E4E8"> textArea </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> document.</span><span style="color: #B392F0">createElement</span><span style="color: #E1E4E8">(</span><span style="color: #9ECBFF">&quot;textarea&quot;</span><span style="color: #E1E4E8">);</span></span>
<span class="line"><span style="color: #E1E4E8">  textArea.style.background </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> </span><span style="color: #9ECBFF">&#39;transparent&#39;</span><span style="color: #E1E4E8">;</span></span>
<span class="line"><span style="color: #E1E4E8">  textArea.value </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> value;</span></span>
<span class="line"><span style="color: #E1E4E8">  document.body.</span><span style="color: #B392F0">appendChild</span><span style="color: #E1E4E8">(textArea);</span></span>
<span class="line"><span style="color: #E1E4E8">  textArea.</span><span style="color: #B392F0">select</span><span style="color: #E1E4E8">();</span></span>
<span class="line"><span style="color: #E1E4E8">  </span><span style="color: #F97583">try</span><span style="color: #E1E4E8"> {</span></span>
<span class="line"><span style="color: #E1E4E8">    </span><span style="color: #F97583">var</span><span style="color: #E1E4E8"> successful </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> document.</span><span style="color: #B392F0">execCommand</span><span style="color: #E1E4E8">(</span><span style="color: #9ECBFF">&#39;copy&#39;</span><span style="color: #E1E4E8">);</span></span>
<span class="line"><span style="color: #E1E4E8">  } </span><span style="color: #F97583">catch</span><span style="color: #E1E4E8"> (err) {</span></span>
<span class="line"><span style="color: #E1E4E8">    console.</span><span style="color: #B392F0">log</span><span style="color: #E1E4E8">(</span><span style="color: #9ECBFF">&#39;Oops, unable to copy&#39;</span><span style="color: #E1E4E8">);</span></span>
<span class="line"><span style="color: #E1E4E8">  }</span></span>
<span class="line"><span style="color: #E1E4E8">  document.body.</span><span style="color: #B392F0">removeChild</span><span style="color: #E1E4E8">(textArea);</span></span>
<span class="line"><span style="color: #E1E4E8">}</span></span></code></pre></div></div></figure>

<h4 id="36-判断类型集合"><a href="#36-判断类型集合" class="headerlink" title="36.判断类型集合"></a>36.判断类型集合</h4><figure class="shiki javascript"><div class='codeblock'><div class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br></pre></div><div class="code"><pre class="shiki github-dark"><code><span class="line"><span style="color: #F97583">export</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">const</span><span style="color: #E1E4E8"> </span><span style="color: #B392F0">checkStr</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> (</span><span style="color: #FFAB70">str</span><span style="color: #E1E4E8">, </span><span style="color: #FFAB70">type</span><span style="color: #E1E4E8">) </span><span style="color: #F97583">=&gt;</span><span style="color: #E1E4E8"> {</span></span>
<span class="line"><span style="color: #E1E4E8">  </span><span style="color: #F97583">switch</span><span style="color: #E1E4E8"> (type) {</span></span>
<span class="line"><span style="color: #E1E4E8">    </span><span style="color: #F97583">case</span><span style="color: #E1E4E8"> </span><span style="color: #9ECBFF">&#39;phone&#39;</span><span style="color: #E1E4E8">:   </span><span style="color: #6A737D">//手机号码</span></span>
<span class="line"><span style="color: #E1E4E8">      </span><span style="color: #F97583">return</span><span style="color: #DBEDFF"> </span><span style="color: #9ECBFF">/</span><span style="color: #F97583">^</span><span style="color: #DBEDFF">1</span><span style="color: #79B8FF">[3|4|5|6|7|8|9][0-9]</span><span style="color: #F97583">{9}$</span><span style="color: #9ECBFF">/</span><span style="color: #E1E4E8">.</span><span style="color: #B392F0">test</span><span style="color: #E1E4E8">(str);</span></span>
<span class="line"><span style="color: #E1E4E8">    </span><span style="color: #F97583">case</span><span style="color: #E1E4E8"> </span><span style="color: #9ECBFF">&#39;tel&#39;</span><span style="color: #E1E4E8">:     </span><span style="color: #6A737D">//座机</span></span>
<span class="line"><span style="color: #E1E4E8">      </span><span style="color: #F97583">return</span><span style="color: #DBEDFF"> </span><span style="color: #9ECBFF">/</span><span style="color: #F97583">^</span><span style="color: #DBEDFF">(0</span><span style="color: #79B8FF">\d</span><span style="color: #F97583">{2,3}</span><span style="color: #DBEDFF">-</span><span style="color: #79B8FF">\d</span><span style="color: #F97583">{7,8}</span><span style="color: #DBEDFF">)(-</span><span style="color: #79B8FF">\d</span><span style="color: #F97583">{1,4}</span><span style="color: #DBEDFF">)</span><span style="color: #F97583">?$</span><span style="color: #9ECBFF">/</span><span style="color: #E1E4E8">.</span><span style="color: #B392F0">test</span><span style="color: #E1E4E8">(str);</span></span>
<span class="line"><span style="color: #E1E4E8">    </span><span style="color: #F97583">case</span><span style="color: #E1E4E8"> </span><span style="color: #9ECBFF">&#39;card&#39;</span><span style="color: #E1E4E8">:    </span><span style="color: #6A737D">//身份证</span></span>
<span class="line"><span style="color: #E1E4E8">      </span><span style="color: #F97583">return</span><span style="color: #9ECBFF"> /</span><span style="color: #DBEDFF">(</span><span style="color: #F97583">^</span><span style="color: #79B8FF">\d</span><span style="color: #F97583">{15}$</span><span style="color: #DBEDFF">)</span><span style="color: #F97583">|</span><span style="color: #DBEDFF">(</span><span style="color: #F97583">^</span><span style="color: #79B8FF">\d</span><span style="color: #F97583">{18}$</span><span style="color: #DBEDFF">)</span><span style="color: #F97583">|</span><span style="color: #DBEDFF">(</span><span style="color: #F97583">^</span><span style="color: #79B8FF">\d</span><span style="color: #F97583">{17}</span><span style="color: #DBEDFF">(</span><span style="color: #79B8FF">\d</span><span style="color: #F97583">|</span><span style="color: #DBEDFF">X</span><span style="color: #F97583">|</span><span style="color: #DBEDFF">x)</span><span style="color: #F97583">$</span><span style="color: #DBEDFF">)</span><span style="color: #9ECBFF">/</span><span style="color: #E1E4E8">.</span><span style="color: #B392F0">test</span><span style="color: #E1E4E8">(str);</span></span>
<span class="line"><span style="color: #E1E4E8">    </span><span style="color: #F97583">case</span><span style="color: #E1E4E8"> </span><span style="color: #9ECBFF">&#39;pwd&#39;</span><span style="color: #E1E4E8">:     </span><span style="color: #6A737D">//密码以字母开头，长度在6~18之间，只能包含字母、数字和下划线</span></span>
<span class="line"><span style="color: #E1E4E8">      </span><span style="color: #F97583">return</span><span style="color: #DBEDFF"> </span><span style="color: #9ECBFF">/</span><span style="color: #F97583">^</span><span style="color: #79B8FF">[a-zA-Z]\w</span><span style="color: #F97583">{5,17}$</span><span style="color: #9ECBFF">/</span><span style="color: #E1E4E8">.</span><span style="color: #B392F0">test</span><span style="color: #E1E4E8">(str)</span></span>
<span class="line"><span style="color: #E1E4E8">    </span><span style="color: #F97583">case</span><span style="color: #E1E4E8"> </span><span style="color: #9ECBFF">&#39;postal&#39;</span><span style="color: #E1E4E8">:  </span><span style="color: #6A737D">//邮政编码</span></span>
<span class="line"><span style="color: #E1E4E8">      </span><span style="color: #F97583">return</span><span style="color: #DBEDFF"> </span><span style="color: #9ECBFF">/</span><span style="color: #79B8FF">[1-9]\d</span><span style="color: #F97583">{5}</span><span style="color: #DBEDFF">(?!</span><span style="color: #79B8FF">\d</span><span style="color: #DBEDFF">)</span><span style="color: #9ECBFF">/</span><span style="color: #E1E4E8">.</span><span style="color: #B392F0">test</span><span style="color: #E1E4E8">(str);</span></span>
<span class="line"><span style="color: #E1E4E8">    </span><span style="color: #F97583">case</span><span style="color: #E1E4E8"> </span><span style="color: #9ECBFF">&#39;QQ&#39;</span><span style="color: #E1E4E8">:      </span><span style="color: #6A737D">//QQ号</span></span>
<span class="line"><span style="color: #E1E4E8">      </span><span style="color: #F97583">return</span><span style="color: #DBEDFF"> </span><span style="color: #9ECBFF">/</span><span style="color: #F97583">^</span><span style="color: #79B8FF">[1-9][0-9]</span><span style="color: #F97583">{4,9}$</span><span style="color: #9ECBFF">/</span><span style="color: #E1E4E8">.</span><span style="color: #B392F0">test</span><span style="color: #E1E4E8">(str);</span></span>
<span class="line"><span style="color: #E1E4E8">    </span><span style="color: #F97583">case</span><span style="color: #E1E4E8"> </span><span style="color: #9ECBFF">&#39;email&#39;</span><span style="color: #E1E4E8">:   </span><span style="color: #6A737D">//邮箱</span></span>
<span class="line"><span style="color: #E1E4E8">      </span><span style="color: #F97583">return</span><span style="color: #DBEDFF"> </span><span style="color: #9ECBFF">/</span><span style="color: #F97583">^</span><span style="color: #79B8FF">[\w-]</span><span style="color: #F97583">+</span><span style="color: #DBEDFF">(</span><span style="color: #85E89D; font-weight: bold">\.</span><span style="color: #79B8FF">[\w-]</span><span style="color: #F97583">+</span><span style="color: #DBEDFF">)</span><span style="color: #F97583">*</span><span style="color: #DBEDFF">@</span><span style="color: #79B8FF">[\w-]</span><span style="color: #F97583">+</span><span style="color: #DBEDFF">(</span><span style="color: #85E89D; font-weight: bold">\.</span><span style="color: #79B8FF">[\w-]</span><span style="color: #F97583">+</span><span style="color: #DBEDFF">)</span><span style="color: #F97583">+$</span><span style="color: #9ECBFF">/</span><span style="color: #E1E4E8">.</span><span style="color: #B392F0">test</span><span style="color: #E1E4E8">(str);</span></span>
<span class="line"><span style="color: #E1E4E8">    </span><span style="color: #F97583">case</span><span style="color: #E1E4E8"> </span><span style="color: #9ECBFF">&#39;money&#39;</span><span style="color: #E1E4E8">:   </span><span style="color: #6A737D">//金额(小数点2位)</span></span>
<span class="line"><span style="color: #E1E4E8">      </span><span style="color: #F97583">return</span><span style="color: #DBEDFF"> </span><span style="color: #9ECBFF">/</span><span style="color: #F97583">^</span><span style="color: #79B8FF">\d</span><span style="color: #F97583">*</span><span style="color: #DBEDFF">(?:</span><span style="color: #85E89D; font-weight: bold">\.</span><span style="color: #79B8FF">\d</span><span style="color: #F97583">{0,2}</span><span style="color: #DBEDFF">)</span><span style="color: #F97583">?$</span><span style="color: #9ECBFF">/</span><span style="color: #E1E4E8">.</span><span style="color: #B392F0">test</span><span style="color: #E1E4E8">(str);</span></span>
<span class="line"><span style="color: #E1E4E8">    </span><span style="color: #F97583">case</span><span style="color: #E1E4E8"> </span><span style="color: #9ECBFF">&#39;URL&#39;</span><span style="color: #E1E4E8">:     </span><span style="color: #6A737D">//网址</span></span>
<span class="line"><span style="color: #E1E4E8">      </span><span style="color: #F97583">return</span><span style="color: #DBEDFF"> </span><span style="color: #9ECBFF">/</span><span style="color: #DBEDFF">(http</span><span style="color: #F97583">|</span><span style="color: #DBEDFF">ftp</span><span style="color: #F97583">|</span><span style="color: #DBEDFF">https):</span><span style="color: #85E89D; font-weight: bold">\/\/</span><span style="color: #79B8FF">[\w\-_]</span><span style="color: #F97583">+</span><span style="color: #DBEDFF">(</span><span style="color: #85E89D; font-weight: bold">\.</span><span style="color: #79B8FF">[\w\-_]</span><span style="color: #F97583">+</span><span style="color: #DBEDFF">)</span><span style="color: #F97583">+</span><span style="color: #DBEDFF">(</span><span style="color: #79B8FF">[\w\-</span><span style="color: #85E89D; font-weight: bold">\.</span><span style="color: #79B8FF">,@?^=%&amp;:/~</span><span style="color: #85E89D; font-weight: bold">\+</span><span style="color: #79B8FF">#]</span><span style="color: #F97583">*</span><span style="color: #79B8FF">[\w\-</span><span style="color: #85E89D; font-weight: bold">\@</span><span style="color: #79B8FF">?^=%&amp;/~</span><span style="color: #85E89D; font-weight: bold">\+</span><span style="color: #79B8FF">#]</span><span style="color: #DBEDFF">)</span><span style="color: #F97583">?</span><span style="color: #9ECBFF">/</span><span style="color: #E1E4E8">.</span><span style="color: #B392F0">test</span><span style="color: #E1E4E8">(str)</span></span>
<span class="line"><span style="color: #E1E4E8">    </span><span style="color: #F97583">case</span><span style="color: #E1E4E8"> </span><span style="color: #9ECBFF">&#39;IP&#39;</span><span style="color: #E1E4E8">:      </span><span style="color: #6A737D">//IP</span></span>
<span class="line"><span style="color: #E1E4E8">      </span><span style="color: #F97583">return</span><span style="color: #9ECBFF"> /</span><span style="color: #DBEDFF">((?:(?:25</span><span style="color: #79B8FF">[0-5]</span><span style="color: #F97583">|</span><span style="color: #DBEDFF">2</span><span style="color: #79B8FF">[0-4]</span><span style="color: #85E89D; font-weight: bold">\\</span><span style="color: #DBEDFF">d</span><span style="color: #F97583">|</span><span style="color: #79B8FF">[01]</span><span style="color: #F97583">?</span><span style="color: #85E89D; font-weight: bold">\\</span><span style="color: #DBEDFF">d</span><span style="color: #F97583">?</span><span style="color: #85E89D; font-weight: bold">\\</span><span style="color: #DBEDFF">d)</span><span style="color: #85E89D; font-weight: bold">\\</span><span style="color: #79B8FF">.</span><span style="color: #DBEDFF">)</span><span style="color: #F97583">{3}</span><span style="color: #DBEDFF">(?:25</span><span style="color: #79B8FF">[0-5]</span><span style="color: #F97583">|</span><span style="color: #DBEDFF">2</span><span style="color: #79B8FF">[0-4]</span><span style="color: #85E89D; font-weight: bold">\\</span><span style="color: #DBEDFF">d</span><span style="color: #F97583">|</span><span style="color: #79B8FF">[01]</span><span style="color: #F97583">?</span><span style="color: #85E89D; font-weight: bold">\\</span><span style="color: #DBEDFF">d</span><span style="color: #F97583">?</span><span style="color: #85E89D; font-weight: bold">\\</span><span style="color: #DBEDFF">d))</span><span style="color: #9ECBFF">/</span><span style="color: #E1E4E8">.</span><span style="color: #B392F0">test</span><span style="color: #E1E4E8">(str);</span></span>
<span class="line"><span style="color: #E1E4E8">    </span><span style="color: #F97583">case</span><span style="color: #E1E4E8"> </span><span style="color: #9ECBFF">&#39;date&#39;</span><span style="color: #E1E4E8">:    </span><span style="color: #6A737D">//日期时间</span></span>
<span class="line"><span style="color: #E1E4E8">      </span><span style="color: #F97583">return</span><span style="color: #9ECBFF"> /</span><span style="color: #F97583">^</span><span style="color: #DBEDFF">(</span><span style="color: #79B8FF">\d</span><span style="color: #F97583">{4}</span><span style="color: #DBEDFF">)</span><span style="color: #85E89D; font-weight: bold">\-</span><span style="color: #DBEDFF">(</span><span style="color: #79B8FF">\d</span><span style="color: #F97583">{2}</span><span style="color: #DBEDFF">)</span><span style="color: #85E89D; font-weight: bold">\-</span><span style="color: #DBEDFF">(</span><span style="color: #79B8FF">\d</span><span style="color: #F97583">{2}</span><span style="color: #DBEDFF">) (</span><span style="color: #79B8FF">\d</span><span style="color: #F97583">{2}</span><span style="color: #DBEDFF">)(?:</span><span style="color: #85E89D; font-weight: bold">\:</span><span style="color: #79B8FF">\d</span><span style="color: #F97583">{2}|</span><span style="color: #DBEDFF">:(</span><span style="color: #79B8FF">\d</span><span style="color: #F97583">{2}</span><span style="color: #DBEDFF">):(</span><span style="color: #79B8FF">\d</span><span style="color: #F97583">{2}</span><span style="color: #DBEDFF">))</span><span style="color: #F97583">$</span><span style="color: #9ECBFF">/</span><span style="color: #E1E4E8">.</span><span style="color: #B392F0">test</span><span style="color: #E1E4E8">(str) </span><span style="color: #F97583">||</span><span style="color: #DBEDFF"> </span><span style="color: #9ECBFF">/</span><span style="color: #F97583">^</span><span style="color: #DBEDFF">(</span><span style="color: #79B8FF">\d</span><span style="color: #F97583">{4}</span><span style="color: #DBEDFF">)</span><span style="color: #85E89D; font-weight: bold">\-</span><span style="color: #DBEDFF">(</span><span style="color: #79B8FF">\d</span><span style="color: #F97583">{2}</span><span style="color: #DBEDFF">)</span><span style="color: #85E89D; font-weight: bold">\-</span><span style="color: #DBEDFF">(</span><span style="color: #79B8FF">\d</span><span style="color: #F97583">{2}</span><span style="color: #DBEDFF">)</span><span style="color: #F97583">$</span><span style="color: #9ECBFF">/</span><span style="color: #E1E4E8">.</span><span style="color: #B392F0">test</span><span style="color: #E1E4E8">(str)</span></span>
<span class="line"><span style="color: #E1E4E8">    </span><span style="color: #F97583">case</span><span style="color: #E1E4E8"> </span><span style="color: #9ECBFF">&#39;number&#39;</span><span style="color: #E1E4E8">:  </span><span style="color: #6A737D">//数字</span></span>
<span class="line"><span style="color: #E1E4E8">      </span><span style="color: #F97583">return</span><span style="color: #DBEDFF"> </span><span style="color: #9ECBFF">/</span><span style="color: #F97583">^</span><span style="color: #79B8FF">[0-9]</span><span style="color: #F97583">$</span><span style="color: #9ECBFF">/</span><span style="color: #E1E4E8">.</span><span style="color: #B392F0">test</span><span style="color: #E1E4E8">(str);</span></span>
<span class="line"><span style="color: #E1E4E8">    </span><span style="color: #F97583">case</span><span style="color: #E1E4E8"> </span><span style="color: #9ECBFF">&#39;english&#39;</span><span style="color: #E1E4E8">: </span><span style="color: #6A737D">//英文</span></span>
<span class="line"><span style="color: #E1E4E8">      </span><span style="color: #F97583">return</span><span style="color: #DBEDFF"> </span><span style="color: #9ECBFF">/</span><span style="color: #F97583">^</span><span style="color: #79B8FF">[a-zA-Z]</span><span style="color: #F97583">+$</span><span style="color: #9ECBFF">/</span><span style="color: #E1E4E8">.</span><span style="color: #B392F0">test</span><span style="color: #E1E4E8">(str);</span></span>
<span class="line"><span style="color: #E1E4E8">    </span><span style="color: #F97583">case</span><span style="color: #E1E4E8"> </span><span style="color: #9ECBFF">&#39;chinese&#39;</span><span style="color: #E1E4E8">: </span><span style="color: #6A737D">//中文</span></span>
<span class="line"><span style="color: #E1E4E8">      </span><span style="color: #F97583">return</span><span style="color: #DBEDFF"> </span><span style="color: #9ECBFF">/</span><span style="color: #F97583">^</span><span style="color: #79B8FF">[</span><span style="color: #85E89D; font-weight: bold">\\</span><span style="color: #79B8FF">u4E00-</span><span style="color: #85E89D; font-weight: bold">\\</span><span style="color: #79B8FF">u9FA5]</span><span style="color: #F97583">+$</span><span style="color: #9ECBFF">/</span><span style="color: #E1E4E8">.</span><span style="color: #B392F0">test</span><span style="color: #E1E4E8">(str);</span></span>
<span class="line"><span style="color: #E1E4E8">    </span><span style="color: #F97583">case</span><span style="color: #E1E4E8"> </span><span style="color: #9ECBFF">&#39;lower&#39;</span><span style="color: #E1E4E8">:   </span><span style="color: #6A737D">//小写</span></span>
<span class="line"><span style="color: #E1E4E8">      </span><span style="color: #F97583">return</span><span style="color: #DBEDFF"> </span><span style="color: #9ECBFF">/</span><span style="color: #F97583">^</span><span style="color: #79B8FF">[a-z]</span><span style="color: #F97583">+$</span><span style="color: #9ECBFF">/</span><span style="color: #E1E4E8">.</span><span style="color: #B392F0">test</span><span style="color: #E1E4E8">(str);</span></span>
<span class="line"><span style="color: #E1E4E8">    </span><span style="color: #F97583">case</span><span style="color: #E1E4E8"> </span><span style="color: #9ECBFF">&#39;upper&#39;</span><span style="color: #E1E4E8">:   </span><span style="color: #6A737D">//大写</span></span>
<span class="line"><span style="color: #E1E4E8">      </span><span style="color: #F97583">return</span><span style="color: #DBEDFF"> </span><span style="color: #9ECBFF">/</span><span style="color: #F97583">^</span><span style="color: #79B8FF">[A-Z]</span><span style="color: #F97583">+$</span><span style="color: #9ECBFF">/</span><span style="color: #E1E4E8">.</span><span style="color: #B392F0">test</span><span style="color: #E1E4E8">(str);</span></span>
<span class="line"><span style="color: #E1E4E8">    </span><span style="color: #F97583">case</span><span style="color: #E1E4E8"> </span><span style="color: #9ECBFF">&#39;HTML&#39;</span><span style="color: #E1E4E8">:    </span><span style="color: #6A737D">//HTML标记</span></span>
<span class="line"><span style="color: #E1E4E8">      </span><span style="color: #F97583">return</span><span style="color: #DBEDFF"> </span><span style="color: #9ECBFF">/</span><span style="color: #DBEDFF">&lt;(&quot;</span><span style="color: #79B8FF">[</span><span style="color: #F97583">^</span><span style="color: #79B8FF">&quot;]</span><span style="color: #F97583">*</span><span style="color: #DBEDFF">&quot;</span><span style="color: #F97583">|</span><span style="color: #DBEDFF">&#39;</span><span style="color: #79B8FF">[</span><span style="color: #F97583">^</span><span style="color: #79B8FF">&#39;]</span><span style="color: #F97583">*</span><span style="color: #DBEDFF">&#39;</span><span style="color: #F97583">|</span><span style="color: #79B8FF">[</span><span style="color: #F97583">^</span><span style="color: #79B8FF">&#39;&quot;&gt;]</span><span style="color: #DBEDFF">)</span><span style="color: #F97583">*</span><span style="color: #DBEDFF">&gt;</span><span style="color: #9ECBFF">/</span><span style="color: #E1E4E8">.</span><span style="color: #B392F0">test</span><span style="color: #E1E4E8">(str);</span></span>
<span class="line"><span style="color: #E1E4E8">    </span><span style="color: #F97583">default</span><span style="color: #E1E4E8">:</span></span>
<span class="line"><span style="color: #E1E4E8">      </span><span style="color: #F97583">return</span><span style="color: #E1E4E8"> </span><span style="color: #79B8FF">true</span><span style="color: #E1E4E8">;</span></span>
<span class="line"><span style="color: #E1E4E8">  }</span></span>
<span class="line"><span style="color: #E1E4E8">}</span></span></code></pre></div></div></figure>

<h4 id="37-严格的身份证校验"><a href="#37-严格的身份证校验" class="headerlink" title="37.严格的身份证校验"></a>37.严格的身份证校验</h4><figure class="shiki javascript"><div class='codeblock'><div class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br></pre></div><div class="code"><pre class="shiki github-dark"><code><span class="line"><span style="color: #F97583">export</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">const</span><span style="color: #E1E4E8"> </span><span style="color: #B392F0">isCardID</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> (</span><span style="color: #FFAB70">sId</span><span style="color: #E1E4E8">) </span><span style="color: #F97583">=&gt;</span><span style="color: #E1E4E8"> {</span></span>
<span class="line"><span style="color: #E1E4E8">  </span><span style="color: #F97583">if</span><span style="color: #E1E4E8"> (</span><span style="color: #F97583">!</span><span style="color: #9ECBFF">/</span><span style="color: #DBEDFF">(</span><span style="color: #F97583">^</span><span style="color: #79B8FF">\d</span><span style="color: #F97583">{15}$</span><span style="color: #DBEDFF">)</span><span style="color: #F97583">|</span><span style="color: #DBEDFF">(</span><span style="color: #F97583">^</span><span style="color: #79B8FF">\d</span><span style="color: #F97583">{17}</span><span style="color: #DBEDFF">(</span><span style="color: #79B8FF">\d</span><span style="color: #F97583">|</span><span style="color: #DBEDFF">X</span><span style="color: #F97583">|</span><span style="color: #DBEDFF">x)</span><span style="color: #F97583">$</span><span style="color: #DBEDFF">)</span><span style="color: #9ECBFF">/</span><span style="color: #E1E4E8">.</span><span style="color: #B392F0">test</span><span style="color: #E1E4E8">(sId)) {</span></span>
<span class="line"><span style="color: #E1E4E8">    console.</span><span style="color: #B392F0">log</span><span style="color: #E1E4E8">(</span><span style="color: #9ECBFF">&#39;你输入的身份证长度或格式错误&#39;</span><span style="color: #E1E4E8">)</span></span>
<span class="line"><span style="color: #E1E4E8">    </span><span style="color: #F97583">return</span><span style="color: #E1E4E8"> </span><span style="color: #79B8FF">false</span></span>
<span class="line"><span style="color: #E1E4E8">  }</span></span>
<span class="line"><span style="color: #E1E4E8">  </span><span style="color: #6A737D">//身份证城市</span></span>
<span class="line"><span style="color: #E1E4E8">  </span><span style="color: #F97583">var</span><span style="color: #E1E4E8"> aCity </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> { </span><span style="color: #79B8FF">11</span><span style="color: #E1E4E8">: </span><span style="color: #9ECBFF">&quot;北京&quot;</span><span style="color: #E1E4E8">, </span><span style="color: #79B8FF">12</span><span style="color: #E1E4E8">: </span><span style="color: #9ECBFF">&quot;天津&quot;</span><span style="color: #E1E4E8">, </span><span style="color: #79B8FF">13</span><span style="color: #E1E4E8">: </span><span style="color: #9ECBFF">&quot;河北&quot;</span><span style="color: #E1E4E8">, </span><span style="color: #79B8FF">14</span><span style="color: #E1E4E8">: </span><span style="color: #9ECBFF">&quot;山西&quot;</span><span style="color: #E1E4E8">, </span><span style="color: #79B8FF">15</span><span style="color: #E1E4E8">: </span><span style="color: #9ECBFF">&quot;内蒙古&quot;</span><span style="color: #E1E4E8">, </span><span style="color: #79B8FF">21</span><span style="color: #E1E4E8">: </span><span style="color: #9ECBFF">&quot;辽宁&quot;</span><span style="color: #E1E4E8">, </span><span style="color: #79B8FF">22</span><span style="color: #E1E4E8">: </span><span style="color: #9ECBFF">&quot;吉林&quot;</span><span style="color: #E1E4E8">, </span><span style="color: #79B8FF">23</span><span style="color: #E1E4E8">: </span><span style="color: #9ECBFF">&quot;黑龙江&quot;</span><span style="color: #E1E4E8">, </span><span style="color: #79B8FF">31</span><span style="color: #E1E4E8">: </span><span style="color: #9ECBFF">&quot;上海&quot;</span><span style="color: #E1E4E8">, </span><span style="color: #79B8FF">32</span><span style="color: #E1E4E8">: </span><span style="color: #9ECBFF">&quot;江苏&quot;</span><span style="color: #E1E4E8">, </span><span style="color: #79B8FF">33</span><span style="color: #E1E4E8">: </span><span style="color: #9ECBFF">&quot;浙江&quot;</span><span style="color: #E1E4E8">, </span><span style="color: #79B8FF">34</span><span style="color: #E1E4E8">: </span><span style="color: #9ECBFF">&quot;安徽&quot;</span><span style="color: #E1E4E8">, </span><span style="color: #79B8FF">35</span><span style="color: #E1E4E8">: </span><span style="color: #9ECBFF">&quot;福建&quot;</span><span style="color: #E1E4E8">, </span><span style="color: #79B8FF">36</span><span style="color: #E1E4E8">: </span><span style="color: #9ECBFF">&quot;江西&quot;</span><span style="color: #E1E4E8">, </span><span style="color: #79B8FF">37</span><span style="color: #E1E4E8">: </span><span style="color: #9ECBFF">&quot;山东&quot;</span><span style="color: #E1E4E8">, </span><span style="color: #79B8FF">41</span><span style="color: #E1E4E8">: </span><span style="color: #9ECBFF">&quot;河南&quot;</span><span style="color: #E1E4E8">, </span><span style="color: #79B8FF">42</span><span style="color: #E1E4E8">: </span><span style="color: #9ECBFF">&quot;湖北&quot;</span><span style="color: #E1E4E8">, </span><span style="color: #79B8FF">43</span><span style="color: #E1E4E8">: </span><span style="color: #9ECBFF">&quot;湖南&quot;</span><span style="color: #E1E4E8">, </span><span style="color: #79B8FF">44</span><span style="color: #E1E4E8">: </span><span style="color: #9ECBFF">&quot;广东&quot;</span><span style="color: #E1E4E8">, </span><span style="color: #79B8FF">45</span><span style="color: #E1E4E8">: </span><span style="color: #9ECBFF">&quot;广西&quot;</span><span style="color: #E1E4E8">, </span><span style="color: #79B8FF">46</span><span style="color: #E1E4E8">: </span><span style="color: #9ECBFF">&quot;海南&quot;</span><span style="color: #E1E4E8">, </span><span style="color: #79B8FF">50</span><span style="color: #E1E4E8">: </span><span style="color: #9ECBFF">&quot;重庆&quot;</span><span style="color: #E1E4E8">, </span><span style="color: #79B8FF">51</span><span style="color: #E1E4E8">: </span><span style="color: #9ECBFF">&quot;四川&quot;</span><span style="color: #E1E4E8">, </span><span style="color: #79B8FF">52</span><span style="color: #E1E4E8">: </span><span style="color: #9ECBFF">&quot;贵州&quot;</span><span style="color: #E1E4E8">, </span><span style="color: #79B8FF">53</span><span style="color: #E1E4E8">: </span><span style="color: #9ECBFF">&quot;云南&quot;</span><span style="color: #E1E4E8">, </span><span style="color: #79B8FF">54</span><span style="color: #E1E4E8">: </span><span style="color: #9ECBFF">&quot;西藏&quot;</span><span style="color: #E1E4E8">, </span><span style="color: #79B8FF">61</span><span style="color: #E1E4E8">: </span><span style="color: #9ECBFF">&quot;陕西&quot;</span><span style="color: #E1E4E8">, </span><span style="color: #79B8FF">62</span><span style="color: #E1E4E8">: </span><span style="color: #9ECBFF">&quot;甘肃&quot;</span><span style="color: #E1E4E8">, </span><span style="color: #79B8FF">63</span><span style="color: #E1E4E8">: </span><span style="color: #9ECBFF">&quot;青海&quot;</span><span style="color: #E1E4E8">, </span><span style="color: #79B8FF">64</span><span style="color: #E1E4E8">: </span><span style="color: #9ECBFF">&quot;宁夏&quot;</span><span style="color: #E1E4E8">, </span><span style="color: #79B8FF">65</span><span style="color: #E1E4E8">: </span><span style="color: #9ECBFF">&quot;新疆&quot;</span><span style="color: #E1E4E8">, </span><span style="color: #79B8FF">71</span><span style="color: #E1E4E8">: </span><span style="color: #9ECBFF">&quot;台湾&quot;</span><span style="color: #E1E4E8">, </span><span style="color: #79B8FF">81</span><span style="color: #E1E4E8">: </span><span style="color: #9ECBFF">&quot;香港&quot;</span><span style="color: #E1E4E8">, </span><span style="color: #79B8FF">82</span><span style="color: #E1E4E8">: </span><span style="color: #9ECBFF">&quot;澳门&quot;</span><span style="color: #E1E4E8">, </span><span style="color: #79B8FF">91</span><span style="color: #E1E4E8">: </span><span style="color: #9ECBFF">&quot;国外&quot;</span><span style="color: #E1E4E8"> };</span></span>
<span class="line"><span style="color: #E1E4E8">  </span><span style="color: #F97583">if</span><span style="color: #E1E4E8"> (</span><span style="color: #F97583">!</span><span style="color: #E1E4E8">aCity[</span><span style="color: #B392F0">parseInt</span><span style="color: #E1E4E8">(sId.</span><span style="color: #B392F0">substr</span><span style="color: #E1E4E8">(</span><span style="color: #79B8FF">0</span><span style="color: #E1E4E8">, </span><span style="color: #79B8FF">2</span><span style="color: #E1E4E8">))]) {</span></span>
<span class="line"><span style="color: #E1E4E8">    console.</span><span style="color: #B392F0">log</span><span style="color: #E1E4E8">(</span><span style="color: #9ECBFF">&#39;你的身份证地区非法&#39;</span><span style="color: #E1E4E8">)</span></span>
<span class="line"><span style="color: #E1E4E8">    </span><span style="color: #F97583">return</span><span style="color: #E1E4E8"> </span><span style="color: #79B8FF">false</span></span>
<span class="line"><span style="color: #E1E4E8">  }</span></span>
<span class="line"></span>
<span class="line"><span style="color: #E1E4E8">  </span><span style="color: #6A737D">// 出生日期验证</span></span>
<span class="line"><span style="color: #E1E4E8">  </span><span style="color: #F97583">var</span><span style="color: #E1E4E8"> sBirthday </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> (sId.</span><span style="color: #B392F0">substr</span><span style="color: #E1E4E8">(</span><span style="color: #79B8FF">6</span><span style="color: #E1E4E8">, </span><span style="color: #79B8FF">4</span><span style="color: #E1E4E8">) </span><span style="color: #F97583">+</span><span style="color: #E1E4E8"> </span><span style="color: #9ECBFF">&quot;-&quot;</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">+</span><span style="color: #E1E4E8"> </span><span style="color: #B392F0">Number</span><span style="color: #E1E4E8">(sId.</span><span style="color: #B392F0">substr</span><span style="color: #E1E4E8">(</span><span style="color: #79B8FF">10</span><span style="color: #E1E4E8">, </span><span style="color: #79B8FF">2</span><span style="color: #E1E4E8">)) </span><span style="color: #F97583">+</span><span style="color: #E1E4E8"> </span><span style="color: #9ECBFF">&quot;-&quot;</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">+</span><span style="color: #E1E4E8"> </span><span style="color: #B392F0">Number</span><span style="color: #E1E4E8">(sId.</span><span style="color: #B392F0">substr</span><span style="color: #E1E4E8">(</span><span style="color: #79B8FF">12</span><span style="color: #E1E4E8">, </span><span style="color: #79B8FF">2</span><span style="color: #E1E4E8">))).</span><span style="color: #B392F0">replace</span><span style="color: #E1E4E8">(</span><span style="color: #9ECBFF">/</span><span style="color: #DBEDFF">-</span><span style="color: #9ECBFF">/</span><span style="color: #F97583">g</span><span style="color: #E1E4E8">, </span><span style="color: #9ECBFF">&quot;/&quot;</span><span style="color: #E1E4E8">),</span></span>
<span class="line"><span style="color: #E1E4E8">    d </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">new</span><span style="color: #E1E4E8"> </span><span style="color: #B392F0">Date</span><span style="color: #E1E4E8">(sBirthday)</span></span>
<span class="line"><span style="color: #E1E4E8">  </span><span style="color: #F97583">if</span><span style="color: #E1E4E8"> (sBirthday </span><span style="color: #F97583">!=</span><span style="color: #E1E4E8"> (d.</span><span style="color: #B392F0">getFullYear</span><span style="color: #E1E4E8">() </span><span style="color: #F97583">+</span><span style="color: #E1E4E8"> </span><span style="color: #9ECBFF">&quot;/&quot;</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">+</span><span style="color: #E1E4E8"> (d.</span><span style="color: #B392F0">getMonth</span><span style="color: #E1E4E8">() </span><span style="color: #F97583">+</span><span style="color: #E1E4E8"> </span><span style="color: #79B8FF">1</span><span style="color: #E1E4E8">) </span><span style="color: #F97583">+</span><span style="color: #E1E4E8"> </span><span style="color: #9ECBFF">&quot;/&quot;</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">+</span><span style="color: #E1E4E8"> d.</span><span style="color: #B392F0">getDate</span><span style="color: #E1E4E8">())) {</span></span>
<span class="line"><span style="color: #E1E4E8">    console.</span><span style="color: #B392F0">log</span><span style="color: #E1E4E8">(</span><span style="color: #9ECBFF">&#39;身份证上的出生日期非法&#39;</span><span style="color: #E1E4E8">)</span></span>
<span class="line"><span style="color: #E1E4E8">    </span><span style="color: #F97583">return</span><span style="color: #E1E4E8"> </span><span style="color: #79B8FF">false</span></span>
<span class="line"><span style="color: #E1E4E8">  }</span></span>
<span class="line"></span>
<span class="line"><span style="color: #E1E4E8">  </span><span style="color: #6A737D">// 身份证号码校验</span></span>
<span class="line"><span style="color: #E1E4E8">  </span><span style="color: #F97583">var</span><span style="color: #E1E4E8"> sum </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> </span><span style="color: #79B8FF">0</span><span style="color: #E1E4E8">,</span></span>
<span class="line"><span style="color: #E1E4E8">    weights </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> [</span><span style="color: #79B8FF">7</span><span style="color: #E1E4E8">, </span><span style="color: #79B8FF">9</span><span style="color: #E1E4E8">, </span><span style="color: #79B8FF">10</span><span style="color: #E1E4E8">, </span><span style="color: #79B8FF">5</span><span style="color: #E1E4E8">, </span><span style="color: #79B8FF">8</span><span style="color: #E1E4E8">, </span><span style="color: #79B8FF">4</span><span style="color: #E1E4E8">, </span><span style="color: #79B8FF">2</span><span style="color: #E1E4E8">, </span><span style="color: #79B8FF">1</span><span style="color: #E1E4E8">, </span><span style="color: #79B8FF">6</span><span style="color: #E1E4E8">, </span><span style="color: #79B8FF">3</span><span style="color: #E1E4E8">, </span><span style="color: #79B8FF">7</span><span style="color: #E1E4E8">, </span><span style="color: #79B8FF">9</span><span style="color: #E1E4E8">, </span><span style="color: #79B8FF">10</span><span style="color: #E1E4E8">, </span><span style="color: #79B8FF">5</span><span style="color: #E1E4E8">, </span><span style="color: #79B8FF">8</span><span style="color: #E1E4E8">, </span><span style="color: #79B8FF">4</span><span style="color: #E1E4E8">, </span><span style="color: #79B8FF">2</span><span style="color: #E1E4E8">],</span></span>
<span class="line"><span style="color: #E1E4E8">    codes </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> </span><span style="color: #9ECBFF">&quot;10X98765432&quot;</span></span>
<span class="line"><span style="color: #E1E4E8">  </span><span style="color: #F97583">for</span><span style="color: #E1E4E8"> (</span><span style="color: #F97583">var</span><span style="color: #E1E4E8"> i </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> </span><span style="color: #79B8FF">0</span><span style="color: #E1E4E8">; i </span><span style="color: #F97583">&lt;</span><span style="color: #E1E4E8"> sId.</span><span style="color: #79B8FF">length</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">-</span><span style="color: #E1E4E8"> </span><span style="color: #79B8FF">1</span><span style="color: #E1E4E8">; i</span><span style="color: #F97583">++</span><span style="color: #E1E4E8">) {</span></span>
<span class="line"><span style="color: #E1E4E8">    sum </span><span style="color: #F97583">+=</span><span style="color: #E1E4E8"> sId[i] </span><span style="color: #F97583">*</span><span style="color: #E1E4E8"> weights[i];</span></span>
<span class="line"><span style="color: #E1E4E8">  }</span></span>
<span class="line"><span style="color: #E1E4E8">  </span><span style="color: #F97583">var</span><span style="color: #E1E4E8"> last </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> codes[sum </span><span style="color: #F97583">%</span><span style="color: #E1E4E8"> </span><span style="color: #79B8FF">11</span><span style="color: #E1E4E8">]; </span><span style="color: #6A737D">//计算出来的最后一位身份证号码</span></span>
<span class="line"><span style="color: #E1E4E8">  </span><span style="color: #F97583">if</span><span style="color: #E1E4E8"> (sId[sId.</span><span style="color: #79B8FF">length</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">-</span><span style="color: #E1E4E8"> </span><span style="color: #79B8FF">1</span><span style="color: #E1E4E8">] </span><span style="color: #F97583">!=</span><span style="color: #E1E4E8"> last) {</span></span>
<span class="line"><span style="color: #E1E4E8">    console.</span><span style="color: #B392F0">log</span><span style="color: #E1E4E8">(</span><span style="color: #9ECBFF">&#39;你输入的身份证号非法&#39;</span><span style="color: #E1E4E8">)</span></span>
<span class="line"><span style="color: #E1E4E8">    </span><span style="color: #F97583">return</span><span style="color: #E1E4E8"> </span><span style="color: #79B8FF">false</span></span>
<span class="line"><span style="color: #E1E4E8">  }</span></span>
<span class="line"></span>
<span class="line"><span style="color: #E1E4E8">  </span><span style="color: #F97583">return</span><span style="color: #E1E4E8"> </span><span style="color: #79B8FF">true</span></span>
<span class="line"><span style="color: #E1E4E8">}</span></span></code></pre></div></div></figure>

<h4 id="38-随机数范围"><a href="#38-随机数范围" class="headerlink" title="38.随机数范围"></a>38.随机数范围</h4><figure class="shiki javascript"><div class='codeblock'><div class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></div><div class="code"><pre class="shiki github-dark"><code><span class="line"><span style="color: #F97583">export</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">const</span><span style="color: #E1E4E8"> </span><span style="color: #B392F0">random</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> (</span><span style="color: #FFAB70">min</span><span style="color: #E1E4E8">, </span><span style="color: #FFAB70">max</span><span style="color: #E1E4E8">) </span><span style="color: #F97583">=&gt;</span><span style="color: #E1E4E8"> {</span></span>
<span class="line"><span style="color: #E1E4E8">  </span><span style="color: #F97583">if</span><span style="color: #E1E4E8"> (</span><span style="color: #79B8FF">arguments</span><span style="color: #E1E4E8">.</span><span style="color: #79B8FF">length</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">===</span><span style="color: #E1E4E8"> </span><span style="color: #79B8FF">2</span><span style="color: #E1E4E8">) {</span></span>
<span class="line"><span style="color: #E1E4E8">    </span><span style="color: #F97583">return</span><span style="color: #E1E4E8"> Math.</span><span style="color: #B392F0">floor</span><span style="color: #E1E4E8">(min </span><span style="color: #F97583">+</span><span style="color: #E1E4E8"> Math.</span><span style="color: #B392F0">random</span><span style="color: #E1E4E8">() </span><span style="color: #F97583">*</span><span style="color: #E1E4E8"> ((max </span><span style="color: #F97583">+</span><span style="color: #E1E4E8"> </span><span style="color: #79B8FF">1</span><span style="color: #E1E4E8">) </span><span style="color: #F97583">-</span><span style="color: #E1E4E8"> min))</span></span>
<span class="line"><span style="color: #E1E4E8">  } </span><span style="color: #F97583">else</span><span style="color: #E1E4E8"> {</span></span>
<span class="line"><span style="color: #E1E4E8">    </span><span style="color: #F97583">return</span><span style="color: #E1E4E8"> </span><span style="color: #79B8FF">null</span><span style="color: #E1E4E8">;</span></span>
<span class="line"><span style="color: #E1E4E8">  }</span></span>
<span class="line"><span style="color: #E1E4E8">}</span></span></code></pre></div></div></figure>

<h4 id="39-将阿拉伯数字翻译成中文的大写数字"><a href="#39-将阿拉伯数字翻译成中文的大写数字" class="headerlink" title="39.将阿拉伯数字翻译成中文的大写数字"></a>39.将阿拉伯数字翻译成中文的大写数字</h4><figure class="shiki javascript"><div class='codeblock'><div class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br></pre></div><div class="code"><pre class="shiki github-dark"><code><span class="line"><span style="color: #F97583">export</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">const</span><span style="color: #E1E4E8"> </span><span style="color: #B392F0">numberToChinese</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> (</span><span style="color: #FFAB70">num</span><span style="color: #E1E4E8">) </span><span style="color: #F97583">=&gt;</span><span style="color: #E1E4E8"> {</span></span>
<span class="line"><span style="color: #E1E4E8">  </span><span style="color: #F97583">var</span><span style="color: #E1E4E8"> </span><span style="color: #79B8FF">AA</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">new</span><span style="color: #E1E4E8"> </span><span style="color: #B392F0">Array</span><span style="color: #E1E4E8">(</span><span style="color: #9ECBFF">&quot;零&quot;</span><span style="color: #E1E4E8">, </span><span style="color: #9ECBFF">&quot;一&quot;</span><span style="color: #E1E4E8">, </span><span style="color: #9ECBFF">&quot;二&quot;</span><span style="color: #E1E4E8">, </span><span style="color: #9ECBFF">&quot;三&quot;</span><span style="color: #E1E4E8">, </span><span style="color: #9ECBFF">&quot;四&quot;</span><span style="color: #E1E4E8">, </span><span style="color: #9ECBFF">&quot;五&quot;</span><span style="color: #E1E4E8">, </span><span style="color: #9ECBFF">&quot;六&quot;</span><span style="color: #E1E4E8">, </span><span style="color: #9ECBFF">&quot;七&quot;</span><span style="color: #E1E4E8">, </span><span style="color: #9ECBFF">&quot;八&quot;</span><span style="color: #E1E4E8">, </span><span style="color: #9ECBFF">&quot;九&quot;</span><span style="color: #E1E4E8">, </span><span style="color: #9ECBFF">&quot;十&quot;</span><span style="color: #E1E4E8">);</span></span>
<span class="line"><span style="color: #E1E4E8">  </span><span style="color: #F97583">var</span><span style="color: #E1E4E8"> </span><span style="color: #79B8FF">BB</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">new</span><span style="color: #E1E4E8"> </span><span style="color: #B392F0">Array</span><span style="color: #E1E4E8">(</span><span style="color: #9ECBFF">&quot;&quot;</span><span style="color: #E1E4E8">, </span><span style="color: #9ECBFF">&quot;十&quot;</span><span style="color: #E1E4E8">, </span><span style="color: #9ECBFF">&quot;百&quot;</span><span style="color: #E1E4E8">, </span><span style="color: #9ECBFF">&quot;仟&quot;</span><span style="color: #E1E4E8">, </span><span style="color: #9ECBFF">&quot;萬&quot;</span><span style="color: #E1E4E8">, </span><span style="color: #9ECBFF">&quot;億&quot;</span><span style="color: #E1E4E8">, </span><span style="color: #9ECBFF">&quot;点&quot;</span><span style="color: #E1E4E8">, </span><span style="color: #9ECBFF">&quot;&quot;</span><span style="color: #E1E4E8">);</span></span>
<span class="line"><span style="color: #E1E4E8">  </span><span style="color: #F97583">var</span><span style="color: #E1E4E8"> a </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> (</span><span style="color: #9ECBFF">&quot;&quot;</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">+</span><span style="color: #E1E4E8"> num).</span><span style="color: #B392F0">replace</span><span style="color: #E1E4E8">(</span><span style="color: #9ECBFF">/</span><span style="color: #DBEDFF">(</span><span style="color: #F97583">^</span><span style="color: #DBEDFF">0</span><span style="color: #F97583">*</span><span style="color: #DBEDFF">)</span><span style="color: #9ECBFF">/</span><span style="color: #F97583">g</span><span style="color: #E1E4E8">, </span><span style="color: #9ECBFF">&quot;&quot;</span><span style="color: #E1E4E8">).</span><span style="color: #B392F0">split</span><span style="color: #E1E4E8">(</span><span style="color: #9ECBFF">&quot;.&quot;</span><span style="color: #E1E4E8">),</span></span>
<span class="line"><span style="color: #E1E4E8">    k </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> </span><span style="color: #79B8FF">0</span><span style="color: #E1E4E8">,</span></span>
<span class="line"><span style="color: #E1E4E8">    re </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> </span><span style="color: #9ECBFF">&quot;&quot;</span><span style="color: #E1E4E8">;</span></span>
<span class="line"><span style="color: #E1E4E8">  </span><span style="color: #F97583">for</span><span style="color: #E1E4E8"> (</span><span style="color: #F97583">var</span><span style="color: #E1E4E8"> i </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> a[</span><span style="color: #79B8FF">0</span><span style="color: #E1E4E8">].</span><span style="color: #79B8FF">length</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">-</span><span style="color: #E1E4E8"> </span><span style="color: #79B8FF">1</span><span style="color: #E1E4E8">; i </span><span style="color: #F97583">&gt;=</span><span style="color: #E1E4E8"> </span><span style="color: #79B8FF">0</span><span style="color: #E1E4E8">; i</span><span style="color: #F97583">--</span><span style="color: #E1E4E8">) {</span></span>
<span class="line"><span style="color: #E1E4E8">    </span><span style="color: #F97583">switch</span><span style="color: #E1E4E8"> (k) {</span></span>
<span class="line"><span style="color: #E1E4E8">      </span><span style="color: #F97583">case</span><span style="color: #E1E4E8"> </span><span style="color: #79B8FF">0</span><span style="color: #E1E4E8">:</span></span>
<span class="line"><span style="color: #E1E4E8">        re </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> </span><span style="color: #79B8FF">BB</span><span style="color: #E1E4E8">[</span><span style="color: #79B8FF">7</span><span style="color: #E1E4E8">] </span><span style="color: #F97583">+</span><span style="color: #E1E4E8"> re;</span></span>
<span class="line"><span style="color: #E1E4E8">        </span><span style="color: #F97583">break</span><span style="color: #E1E4E8">;</span></span>
<span class="line"><span style="color: #E1E4E8">      </span><span style="color: #F97583">case</span><span style="color: #E1E4E8"> </span><span style="color: #79B8FF">4</span><span style="color: #E1E4E8">:</span></span>
<span class="line"><span style="color: #E1E4E8">        </span><span style="color: #F97583">if</span><span style="color: #E1E4E8"> (</span><span style="color: #F97583">!new</span><span style="color: #E1E4E8"> </span><span style="color: #B392F0">RegExp</span><span style="color: #E1E4E8">(</span><span style="color: #9ECBFF">&quot;0{4}//d{&quot;</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">+</span><span style="color: #E1E4E8"> (a[</span><span style="color: #79B8FF">0</span><span style="color: #E1E4E8">].</span><span style="color: #79B8FF">length</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">-</span><span style="color: #E1E4E8"> i </span><span style="color: #F97583">-</span><span style="color: #E1E4E8"> </span><span style="color: #79B8FF">1</span><span style="color: #E1E4E8">) </span><span style="color: #F97583">+</span><span style="color: #E1E4E8"> </span><span style="color: #9ECBFF">&quot;}$&quot;</span><span style="color: #E1E4E8">)</span></span>
<span class="line"><span style="color: #E1E4E8">          .</span><span style="color: #B392F0">test</span><span style="color: #E1E4E8">(a[</span><span style="color: #79B8FF">0</span><span style="color: #E1E4E8">]))</span></span>
<span class="line"><span style="color: #E1E4E8">          re </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> </span><span style="color: #79B8FF">BB</span><span style="color: #E1E4E8">[</span><span style="color: #79B8FF">4</span><span style="color: #E1E4E8">] </span><span style="color: #F97583">+</span><span style="color: #E1E4E8"> re;</span></span>
<span class="line"><span style="color: #E1E4E8">        </span><span style="color: #F97583">break</span><span style="color: #E1E4E8">;</span></span>
<span class="line"><span style="color: #E1E4E8">      </span><span style="color: #F97583">case</span><span style="color: #E1E4E8"> </span><span style="color: #79B8FF">8</span><span style="color: #E1E4E8">:</span></span>
<span class="line"><span style="color: #E1E4E8">        re </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> </span><span style="color: #79B8FF">BB</span><span style="color: #E1E4E8">[</span><span style="color: #79B8FF">5</span><span style="color: #E1E4E8">] </span><span style="color: #F97583">+</span><span style="color: #E1E4E8"> re;</span></span>
<span class="line"><span style="color: #E1E4E8">        </span><span style="color: #79B8FF">BB</span><span style="color: #E1E4E8">[</span><span style="color: #79B8FF">7</span><span style="color: #E1E4E8">] </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> </span><span style="color: #79B8FF">BB</span><span style="color: #E1E4E8">[</span><span style="color: #79B8FF">5</span><span style="color: #E1E4E8">];</span></span>
<span class="line"><span style="color: #E1E4E8">        k </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> </span><span style="color: #79B8FF">0</span><span style="color: #E1E4E8">;</span></span>
<span class="line"><span style="color: #E1E4E8">        </span><span style="color: #F97583">break</span><span style="color: #E1E4E8">;</span></span>
<span class="line"><span style="color: #E1E4E8">    }</span></span>
<span class="line"><span style="color: #E1E4E8">    </span><span style="color: #F97583">if</span><span style="color: #E1E4E8"> (k </span><span style="color: #F97583">%</span><span style="color: #E1E4E8"> </span><span style="color: #79B8FF">4</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">==</span><span style="color: #E1E4E8"> </span><span style="color: #79B8FF">2</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">&amp;&amp;</span><span style="color: #E1E4E8"> a[</span><span style="color: #79B8FF">0</span><span style="color: #E1E4E8">].</span><span style="color: #B392F0">charAt</span><span style="color: #E1E4E8">(i </span><span style="color: #F97583">+</span><span style="color: #E1E4E8"> </span><span style="color: #79B8FF">2</span><span style="color: #E1E4E8">) </span><span style="color: #F97583">!=</span><span style="color: #E1E4E8"> </span><span style="color: #79B8FF">0</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">&amp;&amp;</span><span style="color: #E1E4E8"> a[</span><span style="color: #79B8FF">0</span><span style="color: #E1E4E8">].</span><span style="color: #B392F0">charAt</span><span style="color: #E1E4E8">(i </span><span style="color: #F97583">+</span><span style="color: #E1E4E8"> </span><span style="color: #79B8FF">1</span><span style="color: #E1E4E8">) </span><span style="color: #F97583">==</span><span style="color: #E1E4E8"> </span><span style="color: #79B8FF">0</span><span style="color: #E1E4E8">)</span></span>
<span class="line"><span style="color: #E1E4E8">      re </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> </span><span style="color: #79B8FF">AA</span><span style="color: #E1E4E8">[</span><span style="color: #79B8FF">0</span><span style="color: #E1E4E8">] </span><span style="color: #F97583">+</span><span style="color: #E1E4E8"> re;</span></span>
<span class="line"><span style="color: #E1E4E8">    </span><span style="color: #F97583">if</span><span style="color: #E1E4E8"> (a[</span><span style="color: #79B8FF">0</span><span style="color: #E1E4E8">].</span><span style="color: #B392F0">charAt</span><span style="color: #E1E4E8">(i) </span><span style="color: #F97583">!=</span><span style="color: #E1E4E8"> </span><span style="color: #79B8FF">0</span><span style="color: #E1E4E8">)</span></span>
<span class="line"><span style="color: #E1E4E8">      re </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> </span><span style="color: #79B8FF">AA</span><span style="color: #E1E4E8">[a[</span><span style="color: #79B8FF">0</span><span style="color: #E1E4E8">].</span><span style="color: #B392F0">charAt</span><span style="color: #E1E4E8">(i)] </span><span style="color: #F97583">+</span><span style="color: #E1E4E8"> </span><span style="color: #79B8FF">BB</span><span style="color: #E1E4E8">[k </span><span style="color: #F97583">%</span><span style="color: #E1E4E8"> </span><span style="color: #79B8FF">4</span><span style="color: #E1E4E8">] </span><span style="color: #F97583">+</span><span style="color: #E1E4E8"> re;</span></span>
<span class="line"><span style="color: #E1E4E8">    k</span><span style="color: #F97583">++</span><span style="color: #E1E4E8">;</span></span>
<span class="line"><span style="color: #E1E4E8">  }</span></span>
<span class="line"></span>
<span class="line"><span style="color: #E1E4E8">  </span><span style="color: #F97583">if</span><span style="color: #E1E4E8"> (a.</span><span style="color: #79B8FF">length</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">&gt;</span><span style="color: #E1E4E8"> </span><span style="color: #79B8FF">1</span><span style="color: #E1E4E8">) </span><span style="color: #6A737D">// 加上小数部分(如果有小数部分)</span></span>
<span class="line"><span style="color: #E1E4E8">  {</span></span>
<span class="line"><span style="color: #E1E4E8">    re </span><span style="color: #F97583">+=</span><span style="color: #E1E4E8"> </span><span style="color: #79B8FF">BB</span><span style="color: #E1E4E8">[</span><span style="color: #79B8FF">6</span><span style="color: #E1E4E8">];</span></span>
<span class="line"><span style="color: #E1E4E8">    </span><span style="color: #F97583">for</span><span style="color: #E1E4E8"> (</span><span style="color: #F97583">var</span><span style="color: #E1E4E8"> i </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> </span><span style="color: #79B8FF">0</span><span style="color: #E1E4E8">; i </span><span style="color: #F97583">&lt;</span><span style="color: #E1E4E8"> a[</span><span style="color: #79B8FF">1</span><span style="color: #E1E4E8">].</span><span style="color: #79B8FF">length</span><span style="color: #E1E4E8">; i</span><span style="color: #F97583">++</span><span style="color: #E1E4E8">)</span></span>
<span class="line"><span style="color: #E1E4E8">      re </span><span style="color: #F97583">+=</span><span style="color: #E1E4E8"> </span><span style="color: #79B8FF">AA</span><span style="color: #E1E4E8">[a[</span><span style="color: #79B8FF">1</span><span style="color: #E1E4E8">].</span><span style="color: #B392F0">charAt</span><span style="color: #E1E4E8">(i)];</span></span>
<span class="line"><span style="color: #E1E4E8">  }</span></span>
<span class="line"><span style="color: #E1E4E8">  </span><span style="color: #F97583">if</span><span style="color: #E1E4E8"> (re </span><span style="color: #F97583">==</span><span style="color: #E1E4E8"> </span><span style="color: #9ECBFF">&#39;一十&#39;</span><span style="color: #E1E4E8">)</span></span>
<span class="line"><span style="color: #E1E4E8">    re </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> </span><span style="color: #9ECBFF">&quot;十&quot;</span><span style="color: #E1E4E8">;</span></span>
<span class="line"><span style="color: #E1E4E8">  </span><span style="color: #F97583">if</span><span style="color: #E1E4E8"> (re.</span><span style="color: #B392F0">match</span><span style="color: #E1E4E8">(</span><span style="color: #9ECBFF">/</span><span style="color: #F97583">^</span><span style="color: #DBEDFF">一</span><span style="color: #9ECBFF">/</span><span style="color: #E1E4E8">) </span><span style="color: #F97583">&amp;&amp;</span><span style="color: #E1E4E8"> re.</span><span style="color: #79B8FF">length</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">==</span><span style="color: #E1E4E8"> </span><span style="color: #79B8FF">3</span><span style="color: #E1E4E8">)</span></span>
<span class="line"><span style="color: #E1E4E8">    re </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> re.</span><span style="color: #B392F0">replace</span><span style="color: #E1E4E8">(</span><span style="color: #9ECBFF">&quot;一&quot;</span><span style="color: #E1E4E8">, </span><span style="color: #9ECBFF">&quot;&quot;</span><span style="color: #E1E4E8">);</span></span>
<span class="line"><span style="color: #E1E4E8">  </span><span style="color: #F97583">return</span><span style="color: #E1E4E8"> re;</span></span>
<span class="line"><span style="color: #E1E4E8">}</span></span></code></pre></div></div></figure>

<h4 id="40-将数字转换为大写金额"><a href="#40-将数字转换为大写金额" class="headerlink" title="40.将数字转换为大写金额"></a>40.将数字转换为大写金额</h4><figure class="shiki javascript"><div class='codeblock'><div class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br><span class="line">124</span><br><span class="line">125</span><br><span class="line">126</span><br><span class="line">127</span><br><span class="line">128</span><br><span class="line">129</span><br><span class="line">130</span><br><span class="line">131</span><br><span class="line">132</span><br><span class="line">133</span><br><span class="line">134</span><br><span class="line">135</span><br><span class="line">136</span><br><span class="line">137</span><br><span class="line">138</span><br><span class="line">139</span><br><span class="line">140</span><br><span class="line">141</span><br><span class="line">142</span><br><span class="line">143</span><br><span class="line">144</span><br><span class="line">145</span><br><span class="line">146</span><br><span class="line">147</span><br><span class="line">148</span><br><span class="line">149</span><br></pre></div><div class="code"><pre class="shiki github-dark"><code><span class="line"><span style="color: #F97583">export</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">const</span><span style="color: #E1E4E8"> </span><span style="color: #B392F0">changeToChinese</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> (</span><span style="color: #FFAB70">Num</span><span style="color: #E1E4E8">) </span><span style="color: #F97583">=&gt;</span><span style="color: #E1E4E8"> {</span></span>
<span class="line"><span style="color: #E1E4E8">  </span><span style="color: #6A737D">//判断如果传递进来的不是字符的话转换为字符</span></span>
<span class="line"><span style="color: #E1E4E8">  </span><span style="color: #F97583">if</span><span style="color: #E1E4E8"> (</span><span style="color: #F97583">typeof</span><span style="color: #E1E4E8"> Num </span><span style="color: #F97583">==</span><span style="color: #E1E4E8"> </span><span style="color: #9ECBFF">&quot;number&quot;</span><span style="color: #E1E4E8">) {</span></span>
<span class="line"><span style="color: #E1E4E8">    Num </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">new</span><span style="color: #E1E4E8"> </span><span style="color: #B392F0">String</span><span style="color: #E1E4E8">(Num);</span></span>
<span class="line"><span style="color: #E1E4E8">  };</span></span>
<span class="line"><span style="color: #E1E4E8">  Num </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> Num.</span><span style="color: #B392F0">replace</span><span style="color: #E1E4E8">(</span><span style="color: #9ECBFF">/</span><span style="color: #DBEDFF">,</span><span style="color: #9ECBFF">/</span><span style="color: #F97583">g</span><span style="color: #E1E4E8">, </span><span style="color: #9ECBFF">&quot;&quot;</span><span style="color: #E1E4E8">) </span><span style="color: #6A737D">//替换tomoney()中的“,”</span></span>
<span class="line"><span style="color: #E1E4E8">  Num </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> Num.</span><span style="color: #B392F0">replace</span><span style="color: #E1E4E8">(</span><span style="color: #9ECBFF">/</span><span style="color: #DBEDFF"> </span><span style="color: #9ECBFF">/</span><span style="color: #F97583">g</span><span style="color: #E1E4E8">, </span><span style="color: #9ECBFF">&quot;&quot;</span><span style="color: #E1E4E8">) </span><span style="color: #6A737D">//替换tomoney()中的空格</span></span>
<span class="line"><span style="color: #E1E4E8">  Num </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> Num.</span><span style="color: #B392F0">replace</span><span style="color: #E1E4E8">(</span><span style="color: #9ECBFF">/</span><span style="color: #DBEDFF">￥</span><span style="color: #9ECBFF">/</span><span style="color: #F97583">g</span><span style="color: #E1E4E8">, </span><span style="color: #9ECBFF">&quot;&quot;</span><span style="color: #E1E4E8">) </span><span style="color: #6A737D">//替换掉可能出现的￥字符</span></span>
<span class="line"><span style="color: #E1E4E8">  </span><span style="color: #F97583">if</span><span style="color: #E1E4E8"> (</span><span style="color: #B392F0">isNaN</span><span style="color: #E1E4E8">(Num)) { </span><span style="color: #6A737D">//验证输入的字符是否为数字</span></span>
<span class="line"><span style="color: #E1E4E8">    </span><span style="color: #6A737D">//alert(&quot;请检查小写金额是否正确&quot;);</span></span>
<span class="line"><span style="color: #E1E4E8">    </span><span style="color: #F97583">return</span><span style="color: #E1E4E8"> </span><span style="color: #9ECBFF">&quot;&quot;</span><span style="color: #E1E4E8">;</span></span>
<span class="line"><span style="color: #E1E4E8">  };</span></span>
<span class="line"><span style="color: #E1E4E8">  </span><span style="color: #6A737D">//字符处理完毕后开始转换，采用前后两部分分别转换</span></span>
<span class="line"><span style="color: #E1E4E8">  </span><span style="color: #F97583">var</span><span style="color: #E1E4E8"> part </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> </span><span style="color: #B392F0">String</span><span style="color: #E1E4E8">(Num).</span><span style="color: #B392F0">split</span><span style="color: #E1E4E8">(</span><span style="color: #9ECBFF">&quot;.&quot;</span><span style="color: #E1E4E8">);</span></span>
<span class="line"><span style="color: #E1E4E8">  </span><span style="color: #F97583">var</span><span style="color: #E1E4E8"> newchar </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> </span><span style="color: #9ECBFF">&quot;&quot;</span><span style="color: #E1E4E8">;</span></span>
<span class="line"><span style="color: #E1E4E8">  </span><span style="color: #6A737D">//小数点前进行转化</span></span>
<span class="line"><span style="color: #E1E4E8">  </span><span style="color: #F97583">for</span><span style="color: #E1E4E8"> (</span><span style="color: #F97583">var</span><span style="color: #E1E4E8"> i </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> part[</span><span style="color: #79B8FF">0</span><span style="color: #E1E4E8">].</span><span style="color: #79B8FF">length</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">-</span><span style="color: #E1E4E8"> </span><span style="color: #79B8FF">1</span><span style="color: #E1E4E8">; i </span><span style="color: #F97583">&gt;=</span><span style="color: #E1E4E8"> </span><span style="color: #79B8FF">0</span><span style="color: #E1E4E8">; i</span><span style="color: #F97583">--</span><span style="color: #E1E4E8">) {</span></span>
<span class="line"><span style="color: #E1E4E8">    </span><span style="color: #F97583">if</span><span style="color: #E1E4E8"> (part[</span><span style="color: #79B8FF">0</span><span style="color: #E1E4E8">].</span><span style="color: #79B8FF">length</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">&gt;</span><span style="color: #E1E4E8"> </span><span style="color: #79B8FF">10</span><span style="color: #E1E4E8">) {</span></span>
<span class="line"><span style="color: #E1E4E8">      </span><span style="color: #F97583">return</span><span style="color: #E1E4E8"> </span><span style="color: #9ECBFF">&quot;&quot;</span><span style="color: #E1E4E8">;</span></span>
<span class="line"><span style="color: #E1E4E8">      </span><span style="color: #6A737D">//若数量超过拾亿单位，提示</span></span>
<span class="line"><span style="color: #E1E4E8">    }</span></span>
<span class="line"><span style="color: #E1E4E8">    </span><span style="color: #F97583">var</span><span style="color: #E1E4E8"> tmpnewchar </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> </span><span style="color: #9ECBFF">&quot;&quot;</span></span>
<span class="line"><span style="color: #E1E4E8">    </span><span style="color: #F97583">var</span><span style="color: #E1E4E8"> perchar </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> part[</span><span style="color: #79B8FF">0</span><span style="color: #E1E4E8">].</span><span style="color: #B392F0">charAt</span><span style="color: #E1E4E8">(i);</span></span>
<span class="line"><span style="color: #E1E4E8">    </span><span style="color: #F97583">switch</span><span style="color: #E1E4E8"> (perchar) {</span></span>
<span class="line"><span style="color: #E1E4E8">      </span><span style="color: #F97583">case</span><span style="color: #E1E4E8"> </span><span style="color: #9ECBFF">&quot;0&quot;</span><span style="color: #E1E4E8">:</span></span>
<span class="line"><span style="color: #E1E4E8">        tmpnewchar </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> </span><span style="color: #9ECBFF">&quot;零&quot;</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">+</span><span style="color: #E1E4E8"> tmpnewchar;</span></span>
<span class="line"><span style="color: #E1E4E8">        </span><span style="color: #F97583">break</span><span style="color: #E1E4E8">;</span></span>
<span class="line"><span style="color: #E1E4E8">      </span><span style="color: #F97583">case</span><span style="color: #E1E4E8"> </span><span style="color: #9ECBFF">&quot;1&quot;</span><span style="color: #E1E4E8">:</span></span>
<span class="line"><span style="color: #E1E4E8">        tmpnewchar </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> </span><span style="color: #9ECBFF">&quot;壹&quot;</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">+</span><span style="color: #E1E4E8"> tmpnewchar;</span></span>
<span class="line"><span style="color: #E1E4E8">        </span><span style="color: #F97583">break</span><span style="color: #E1E4E8">;</span></span>
<span class="line"><span style="color: #E1E4E8">      </span><span style="color: #F97583">case</span><span style="color: #E1E4E8"> </span><span style="color: #9ECBFF">&quot;2&quot;</span><span style="color: #E1E4E8">:</span></span>
<span class="line"><span style="color: #E1E4E8">        tmpnewchar </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> </span><span style="color: #9ECBFF">&quot;贰&quot;</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">+</span><span style="color: #E1E4E8"> tmpnewchar;</span></span>
<span class="line"><span style="color: #E1E4E8">        </span><span style="color: #F97583">break</span><span style="color: #E1E4E8">;</span></span>
<span class="line"><span style="color: #E1E4E8">      </span><span style="color: #F97583">case</span><span style="color: #E1E4E8"> </span><span style="color: #9ECBFF">&quot;3&quot;</span><span style="color: #E1E4E8">:</span></span>
<span class="line"><span style="color: #E1E4E8">        tmpnewchar </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> </span><span style="color: #9ECBFF">&quot;叁&quot;</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">+</span><span style="color: #E1E4E8"> tmpnewchar;</span></span>
<span class="line"><span style="color: #E1E4E8">        </span><span style="color: #F97583">break</span><span style="color: #E1E4E8">;</span></span>
<span class="line"><span style="color: #E1E4E8">      </span><span style="color: #F97583">case</span><span style="color: #E1E4E8"> </span><span style="color: #9ECBFF">&quot;4&quot;</span><span style="color: #E1E4E8">:</span></span>
<span class="line"><span style="color: #E1E4E8">        tmpnewchar </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> </span><span style="color: #9ECBFF">&quot;肆&quot;</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">+</span><span style="color: #E1E4E8"> tmpnewchar;</span></span>
<span class="line"><span style="color: #E1E4E8">        </span><span style="color: #F97583">break</span><span style="color: #E1E4E8">;</span></span>
<span class="line"><span style="color: #E1E4E8">      </span><span style="color: #F97583">case</span><span style="color: #E1E4E8"> </span><span style="color: #9ECBFF">&quot;5&quot;</span><span style="color: #E1E4E8">:</span></span>
<span class="line"><span style="color: #E1E4E8">        tmpnewchar </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> </span><span style="color: #9ECBFF">&quot;伍&quot;</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">+</span><span style="color: #E1E4E8"> tmpnewchar;</span></span>
<span class="line"><span style="color: #E1E4E8">        </span><span style="color: #F97583">break</span><span style="color: #E1E4E8">;</span></span>
<span class="line"><span style="color: #E1E4E8">      </span><span style="color: #F97583">case</span><span style="color: #E1E4E8"> </span><span style="color: #9ECBFF">&quot;6&quot;</span><span style="color: #E1E4E8">:</span></span>
<span class="line"><span style="color: #E1E4E8">        tmpnewchar </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> </span><span style="color: #9ECBFF">&quot;陆&quot;</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">+</span><span style="color: #E1E4E8"> tmpnewchar;</span></span>
<span class="line"><span style="color: #E1E4E8">        </span><span style="color: #F97583">break</span><span style="color: #E1E4E8">;</span></span>
<span class="line"><span style="color: #E1E4E8">      </span><span style="color: #F97583">case</span><span style="color: #E1E4E8"> </span><span style="color: #9ECBFF">&quot;7&quot;</span><span style="color: #E1E4E8">:</span></span>
<span class="line"><span style="color: #E1E4E8">        tmpnewchar </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> </span><span style="color: #9ECBFF">&quot;柒&quot;</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">+</span><span style="color: #E1E4E8"> tmpnewchar;</span></span>
<span class="line"><span style="color: #E1E4E8">        </span><span style="color: #F97583">break</span><span style="color: #E1E4E8">;</span></span>
<span class="line"><span style="color: #E1E4E8">      </span><span style="color: #F97583">case</span><span style="color: #E1E4E8"> </span><span style="color: #9ECBFF">&quot;8&quot;</span><span style="color: #E1E4E8">:</span></span>
<span class="line"><span style="color: #E1E4E8">        tmpnewchar </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> </span><span style="color: #9ECBFF">&quot;捌&quot;</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">+</span><span style="color: #E1E4E8"> tmpnewchar;</span></span>
<span class="line"><span style="color: #E1E4E8">        </span><span style="color: #F97583">break</span><span style="color: #E1E4E8">;</span></span>
<span class="line"><span style="color: #E1E4E8">      </span><span style="color: #F97583">case</span><span style="color: #E1E4E8"> </span><span style="color: #9ECBFF">&quot;9&quot;</span><span style="color: #E1E4E8">:</span></span>
<span class="line"><span style="color: #E1E4E8">        tmpnewchar </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> </span><span style="color: #9ECBFF">&quot;玖&quot;</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">+</span><span style="color: #E1E4E8"> tmpnewchar;</span></span>
<span class="line"><span style="color: #E1E4E8">        </span><span style="color: #F97583">break</span><span style="color: #E1E4E8">;</span></span>
<span class="line"><span style="color: #E1E4E8">    }</span></span>
<span class="line"><span style="color: #E1E4E8">    </span><span style="color: #F97583">switch</span><span style="color: #E1E4E8"> (part[</span><span style="color: #79B8FF">0</span><span style="color: #E1E4E8">].</span><span style="color: #79B8FF">length</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">-</span><span style="color: #E1E4E8"> i </span><span style="color: #F97583">-</span><span style="color: #E1E4E8"> </span><span style="color: #79B8FF">1</span><span style="color: #E1E4E8">) {</span></span>
<span class="line"><span style="color: #E1E4E8">      </span><span style="color: #F97583">case</span><span style="color: #E1E4E8"> </span><span style="color: #79B8FF">0</span><span style="color: #E1E4E8">:</span></span>
<span class="line"><span style="color: #E1E4E8">        tmpnewchar </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> tmpnewchar </span><span style="color: #F97583">+</span><span style="color: #E1E4E8"> </span><span style="color: #9ECBFF">&quot;元&quot;</span><span style="color: #E1E4E8">;</span></span>
<span class="line"><span style="color: #E1E4E8">        </span><span style="color: #F97583">break</span><span style="color: #E1E4E8">;</span></span>
<span class="line"><span style="color: #E1E4E8">      </span><span style="color: #F97583">case</span><span style="color: #E1E4E8"> </span><span style="color: #79B8FF">1</span><span style="color: #E1E4E8">:</span></span>
<span class="line"><span style="color: #E1E4E8">        </span><span style="color: #F97583">if</span><span style="color: #E1E4E8"> (perchar </span><span style="color: #F97583">!=</span><span style="color: #E1E4E8"> </span><span style="color: #79B8FF">0</span><span style="color: #E1E4E8">) tmpnewchar </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> tmpnewchar </span><span style="color: #F97583">+</span><span style="color: #E1E4E8"> </span><span style="color: #9ECBFF">&quot;拾&quot;</span><span style="color: #E1E4E8">;</span></span>
<span class="line"><span style="color: #E1E4E8">        </span><span style="color: #F97583">break</span><span style="color: #E1E4E8">;</span></span>
<span class="line"><span style="color: #E1E4E8">      </span><span style="color: #F97583">case</span><span style="color: #E1E4E8"> </span><span style="color: #79B8FF">2</span><span style="color: #E1E4E8">:</span></span>
<span class="line"><span style="color: #E1E4E8">        </span><span style="color: #F97583">if</span><span style="color: #E1E4E8"> (perchar </span><span style="color: #F97583">!=</span><span style="color: #E1E4E8"> </span><span style="color: #79B8FF">0</span><span style="color: #E1E4E8">) tmpnewchar </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> tmpnewchar </span><span style="color: #F97583">+</span><span style="color: #E1E4E8"> </span><span style="color: #9ECBFF">&quot;佰&quot;</span><span style="color: #E1E4E8">;</span></span>
<span class="line"><span style="color: #E1E4E8">        </span><span style="color: #F97583">break</span><span style="color: #E1E4E8">;</span></span>
<span class="line"><span style="color: #E1E4E8">      </span><span style="color: #F97583">case</span><span style="color: #E1E4E8"> </span><span style="color: #79B8FF">3</span><span style="color: #E1E4E8">:</span></span>
<span class="line"><span style="color: #E1E4E8">        </span><span style="color: #F97583">if</span><span style="color: #E1E4E8"> (perchar </span><span style="color: #F97583">!=</span><span style="color: #E1E4E8"> </span><span style="color: #79B8FF">0</span><span style="color: #E1E4E8">) tmpnewchar </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> tmpnewchar </span><span style="color: #F97583">+</span><span style="color: #E1E4E8"> </span><span style="color: #9ECBFF">&quot;仟&quot;</span><span style="color: #E1E4E8">;</span></span>
<span class="line"><span style="color: #E1E4E8">        </span><span style="color: #F97583">break</span><span style="color: #E1E4E8">;</span></span>
<span class="line"><span style="color: #E1E4E8">      </span><span style="color: #F97583">case</span><span style="color: #E1E4E8"> </span><span style="color: #79B8FF">4</span><span style="color: #E1E4E8">:</span></span>
<span class="line"><span style="color: #E1E4E8">        tmpnewchar </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> tmpnewchar </span><span style="color: #F97583">+</span><span style="color: #E1E4E8"> </span><span style="color: #9ECBFF">&quot;万&quot;</span><span style="color: #E1E4E8">;</span></span>
<span class="line"><span style="color: #E1E4E8">        </span><span style="color: #F97583">break</span><span style="color: #E1E4E8">;</span></span>
<span class="line"><span style="color: #E1E4E8">      </span><span style="color: #F97583">case</span><span style="color: #E1E4E8"> </span><span style="color: #79B8FF">5</span><span style="color: #E1E4E8">:</span></span>
<span class="line"><span style="color: #E1E4E8">        </span><span style="color: #F97583">if</span><span style="color: #E1E4E8"> (perchar </span><span style="color: #F97583">!=</span><span style="color: #E1E4E8"> </span><span style="color: #79B8FF">0</span><span style="color: #E1E4E8">) tmpnewchar </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> tmpnewchar </span><span style="color: #F97583">+</span><span style="color: #E1E4E8"> </span><span style="color: #9ECBFF">&quot;拾&quot;</span><span style="color: #E1E4E8">;</span></span>
<span class="line"><span style="color: #E1E4E8">        </span><span style="color: #F97583">break</span><span style="color: #E1E4E8">;</span></span>
<span class="line"><span style="color: #E1E4E8">      </span><span style="color: #F97583">case</span><span style="color: #E1E4E8"> </span><span style="color: #79B8FF">6</span><span style="color: #E1E4E8">:</span></span>
<span class="line"><span style="color: #E1E4E8">        </span><span style="color: #F97583">if</span><span style="color: #E1E4E8"> (perchar </span><span style="color: #F97583">!=</span><span style="color: #E1E4E8"> </span><span style="color: #79B8FF">0</span><span style="color: #E1E4E8">) tmpnewchar </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> tmpnewchar </span><span style="color: #F97583">+</span><span style="color: #E1E4E8"> </span><span style="color: #9ECBFF">&quot;佰&quot;</span><span style="color: #E1E4E8">;</span></span>
<span class="line"><span style="color: #E1E4E8">        </span><span style="color: #F97583">break</span><span style="color: #E1E4E8">;</span></span>
<span class="line"><span style="color: #E1E4E8">      </span><span style="color: #F97583">case</span><span style="color: #E1E4E8"> </span><span style="color: #79B8FF">7</span><span style="color: #E1E4E8">:</span></span>
<span class="line"><span style="color: #E1E4E8">        </span><span style="color: #F97583">if</span><span style="color: #E1E4E8"> (perchar </span><span style="color: #F97583">!=</span><span style="color: #E1E4E8"> </span><span style="color: #79B8FF">0</span><span style="color: #E1E4E8">) tmpnewchar </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> tmpnewchar </span><span style="color: #F97583">+</span><span style="color: #E1E4E8"> </span><span style="color: #9ECBFF">&quot;仟&quot;</span><span style="color: #E1E4E8">;</span></span>
<span class="line"><span style="color: #E1E4E8">        </span><span style="color: #F97583">break</span><span style="color: #E1E4E8">;</span></span>
<span class="line"><span style="color: #E1E4E8">      </span><span style="color: #F97583">case</span><span style="color: #E1E4E8"> </span><span style="color: #79B8FF">8</span><span style="color: #E1E4E8">:</span></span>
<span class="line"><span style="color: #E1E4E8">        tmpnewchar </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> tmpnewchar </span><span style="color: #F97583">+</span><span style="color: #E1E4E8"> </span><span style="color: #9ECBFF">&quot;亿&quot;</span><span style="color: #E1E4E8">;</span></span>
<span class="line"><span style="color: #E1E4E8">        </span><span style="color: #F97583">break</span><span style="color: #E1E4E8">;</span></span>
<span class="line"><span style="color: #E1E4E8">      </span><span style="color: #F97583">case</span><span style="color: #E1E4E8"> </span><span style="color: #79B8FF">9</span><span style="color: #E1E4E8">:</span></span>
<span class="line"><span style="color: #E1E4E8">        tmpnewchar </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> tmpnewchar </span><span style="color: #F97583">+</span><span style="color: #E1E4E8"> </span><span style="color: #9ECBFF">&quot;拾&quot;</span><span style="color: #E1E4E8">;</span></span>
<span class="line"><span style="color: #E1E4E8">        </span><span style="color: #F97583">break</span><span style="color: #E1E4E8">;</span></span>
<span class="line"><span style="color: #E1E4E8">    }</span></span>
<span class="line"><span style="color: #E1E4E8">    </span><span style="color: #F97583">var</span><span style="color: #E1E4E8"> newchar </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> tmpnewchar </span><span style="color: #F97583">+</span><span style="color: #E1E4E8"> newchar;</span></span>
<span class="line"><span style="color: #E1E4E8">  }</span></span>
<span class="line"><span style="color: #E1E4E8">  </span><span style="color: #6A737D">//小数点之后进行转化</span></span>
<span class="line"><span style="color: #E1E4E8">  </span><span style="color: #F97583">if</span><span style="color: #E1E4E8"> (Num.</span><span style="color: #B392F0">indexOf</span><span style="color: #E1E4E8">(</span><span style="color: #9ECBFF">&quot;.&quot;</span><span style="color: #E1E4E8">) </span><span style="color: #F97583">!=</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">-</span><span style="color: #79B8FF">1</span><span style="color: #E1E4E8">) {</span></span>
<span class="line"><span style="color: #E1E4E8">    </span><span style="color: #F97583">if</span><span style="color: #E1E4E8"> (part[</span><span style="color: #79B8FF">1</span><span style="color: #E1E4E8">].</span><span style="color: #79B8FF">length</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">&gt;</span><span style="color: #E1E4E8"> </span><span style="color: #79B8FF">2</span><span style="color: #E1E4E8">) {</span></span>
<span class="line"><span style="color: #E1E4E8">      </span><span style="color: #6A737D">// alert(&quot;小数点之后只能保留两位,系统将自动截断&quot;);</span></span>
<span class="line"><span style="color: #E1E4E8">      part[</span><span style="color: #79B8FF">1</span><span style="color: #E1E4E8">] </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> part[</span><span style="color: #79B8FF">1</span><span style="color: #E1E4E8">].</span><span style="color: #B392F0">substr</span><span style="color: #E1E4E8">(</span><span style="color: #79B8FF">0</span><span style="color: #E1E4E8">, </span><span style="color: #79B8FF">2</span><span style="color: #E1E4E8">)</span></span>
<span class="line"><span style="color: #E1E4E8">    }</span></span>
<span class="line"><span style="color: #E1E4E8">    </span><span style="color: #F97583">for</span><span style="color: #E1E4E8"> (i </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> </span><span style="color: #79B8FF">0</span><span style="color: #E1E4E8">; i </span><span style="color: #F97583">&lt;</span><span style="color: #E1E4E8"> part[</span><span style="color: #79B8FF">1</span><span style="color: #E1E4E8">].</span><span style="color: #79B8FF">length</span><span style="color: #E1E4E8">; i</span><span style="color: #F97583">++</span><span style="color: #E1E4E8">) {</span></span>
<span class="line"><span style="color: #E1E4E8">      tmpnewchar </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> </span><span style="color: #9ECBFF">&quot;&quot;</span></span>
<span class="line"><span style="color: #E1E4E8">      perchar </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> part[</span><span style="color: #79B8FF">1</span><span style="color: #E1E4E8">].</span><span style="color: #B392F0">charAt</span><span style="color: #E1E4E8">(i)</span></span>
<span class="line"><span style="color: #E1E4E8">      </span><span style="color: #F97583">switch</span><span style="color: #E1E4E8"> (perchar) {</span></span>
<span class="line"><span style="color: #E1E4E8">        </span><span style="color: #F97583">case</span><span style="color: #E1E4E8"> </span><span style="color: #9ECBFF">&quot;0&quot;</span><span style="color: #E1E4E8">:</span></span>
<span class="line"><span style="color: #E1E4E8">          tmpnewchar </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> </span><span style="color: #9ECBFF">&quot;零&quot;</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">+</span><span style="color: #E1E4E8"> tmpnewchar;</span></span>
<span class="line"><span style="color: #E1E4E8">          </span><span style="color: #F97583">break</span><span style="color: #E1E4E8">;</span></span>
<span class="line"><span style="color: #E1E4E8">        </span><span style="color: #F97583">case</span><span style="color: #E1E4E8"> </span><span style="color: #9ECBFF">&quot;1&quot;</span><span style="color: #E1E4E8">:</span></span>
<span class="line"><span style="color: #E1E4E8">          tmpnewchar </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> </span><span style="color: #9ECBFF">&quot;壹&quot;</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">+</span><span style="color: #E1E4E8"> tmpnewchar;</span></span>
<span class="line"><span style="color: #E1E4E8">          </span><span style="color: #F97583">break</span><span style="color: #E1E4E8">;</span></span>
<span class="line"><span style="color: #E1E4E8">        </span><span style="color: #F97583">case</span><span style="color: #E1E4E8"> </span><span style="color: #9ECBFF">&quot;2&quot;</span><span style="color: #E1E4E8">:</span></span>
<span class="line"><span style="color: #E1E4E8">          tmpnewchar </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> </span><span style="color: #9ECBFF">&quot;贰&quot;</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">+</span><span style="color: #E1E4E8"> tmpnewchar;</span></span>
<span class="line"><span style="color: #E1E4E8">          </span><span style="color: #F97583">break</span><span style="color: #E1E4E8">;</span></span>
<span class="line"><span style="color: #E1E4E8">        </span><span style="color: #F97583">case</span><span style="color: #E1E4E8"> </span><span style="color: #9ECBFF">&quot;3&quot;</span><span style="color: #E1E4E8">:</span></span>
<span class="line"><span style="color: #E1E4E8">          tmpnewchar </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> </span><span style="color: #9ECBFF">&quot;叁&quot;</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">+</span><span style="color: #E1E4E8"> tmpnewchar;</span></span>
<span class="line"><span style="color: #E1E4E8">          </span><span style="color: #F97583">break</span><span style="color: #E1E4E8">;</span></span>
<span class="line"><span style="color: #E1E4E8">        </span><span style="color: #F97583">case</span><span style="color: #E1E4E8"> </span><span style="color: #9ECBFF">&quot;4&quot;</span><span style="color: #E1E4E8">:</span></span>
<span class="line"><span style="color: #E1E4E8">          tmpnewchar </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> </span><span style="color: #9ECBFF">&quot;肆&quot;</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">+</span><span style="color: #E1E4E8"> tmpnewchar;</span></span>
<span class="line"><span style="color: #E1E4E8">          </span><span style="color: #F97583">break</span><span style="color: #E1E4E8">;</span></span>
<span class="line"><span style="color: #E1E4E8">        </span><span style="color: #F97583">case</span><span style="color: #E1E4E8"> </span><span style="color: #9ECBFF">&quot;5&quot;</span><span style="color: #E1E4E8">:</span></span>
<span class="line"><span style="color: #E1E4E8">          tmpnewchar </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> </span><span style="color: #9ECBFF">&quot;伍&quot;</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">+</span><span style="color: #E1E4E8"> tmpnewchar;</span></span>
<span class="line"><span style="color: #E1E4E8">          </span><span style="color: #F97583">break</span><span style="color: #E1E4E8">;</span></span>
<span class="line"><span style="color: #E1E4E8">        </span><span style="color: #F97583">case</span><span style="color: #E1E4E8"> </span><span style="color: #9ECBFF">&quot;6&quot;</span><span style="color: #E1E4E8">:</span></span>
<span class="line"><span style="color: #E1E4E8">          tmpnewchar </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> </span><span style="color: #9ECBFF">&quot;陆&quot;</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">+</span><span style="color: #E1E4E8"> tmpnewchar;</span></span>
<span class="line"><span style="color: #E1E4E8">          </span><span style="color: #F97583">break</span><span style="color: #E1E4E8">;</span></span>
<span class="line"><span style="color: #E1E4E8">        </span><span style="color: #F97583">case</span><span style="color: #E1E4E8"> </span><span style="color: #9ECBFF">&quot;7&quot;</span><span style="color: #E1E4E8">:</span></span>
<span class="line"><span style="color: #E1E4E8">          tmpnewchar </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> </span><span style="color: #9ECBFF">&quot;柒&quot;</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">+</span><span style="color: #E1E4E8"> tmpnewchar;</span></span>
<span class="line"><span style="color: #E1E4E8">          </span><span style="color: #F97583">break</span><span style="color: #E1E4E8">;</span></span>
<span class="line"><span style="color: #E1E4E8">        </span><span style="color: #F97583">case</span><span style="color: #E1E4E8"> </span><span style="color: #9ECBFF">&quot;8&quot;</span><span style="color: #E1E4E8">:</span></span>
<span class="line"><span style="color: #E1E4E8">          tmpnewchar </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> </span><span style="color: #9ECBFF">&quot;捌&quot;</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">+</span><span style="color: #E1E4E8"> tmpnewchar;</span></span>
<span class="line"><span style="color: #E1E4E8">          </span><span style="color: #F97583">break</span><span style="color: #E1E4E8">;</span></span>
<span class="line"><span style="color: #E1E4E8">        </span><span style="color: #F97583">case</span><span style="color: #E1E4E8"> </span><span style="color: #9ECBFF">&quot;9&quot;</span><span style="color: #E1E4E8">:</span></span>
<span class="line"><span style="color: #E1E4E8">          tmpnewchar </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> </span><span style="color: #9ECBFF">&quot;玖&quot;</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">+</span><span style="color: #E1E4E8"> tmpnewchar;</span></span>
<span class="line"><span style="color: #E1E4E8">          </span><span style="color: #F97583">break</span><span style="color: #E1E4E8">;</span></span>
<span class="line"><span style="color: #E1E4E8">      }</span></span>
<span class="line"><span style="color: #E1E4E8">      </span><span style="color: #F97583">if</span><span style="color: #E1E4E8"> (i </span><span style="color: #F97583">==</span><span style="color: #E1E4E8"> </span><span style="color: #79B8FF">0</span><span style="color: #E1E4E8">) tmpnewchar </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> tmpnewchar </span><span style="color: #F97583">+</span><span style="color: #E1E4E8"> </span><span style="color: #9ECBFF">&quot;角&quot;</span><span style="color: #E1E4E8">;</span></span>
<span class="line"><span style="color: #E1E4E8">      </span><span style="color: #F97583">if</span><span style="color: #E1E4E8"> (i </span><span style="color: #F97583">==</span><span style="color: #E1E4E8"> </span><span style="color: #79B8FF">1</span><span style="color: #E1E4E8">) tmpnewchar </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> tmpnewchar </span><span style="color: #F97583">+</span><span style="color: #E1E4E8"> </span><span style="color: #9ECBFF">&quot;分&quot;</span><span style="color: #E1E4E8">;</span></span>
<span class="line"><span style="color: #E1E4E8">      newchar </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> newchar </span><span style="color: #F97583">+</span><span style="color: #E1E4E8"> tmpnewchar;</span></span>
<span class="line"><span style="color: #E1E4E8">    }</span></span>
<span class="line"><span style="color: #E1E4E8">  }</span></span>
<span class="line"><span style="color: #E1E4E8">  </span><span style="color: #6A737D">//替换所有无用汉字</span></span>
<span class="line"><span style="color: #E1E4E8">  </span><span style="color: #F97583">while</span><span style="color: #E1E4E8"> (newchar.</span><span style="color: #B392F0">search</span><span style="color: #E1E4E8">(</span><span style="color: #9ECBFF">&quot;零零&quot;</span><span style="color: #E1E4E8">) </span><span style="color: #F97583">!=</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">-</span><span style="color: #79B8FF">1</span><span style="color: #E1E4E8">)</span></span>
<span class="line"><span style="color: #E1E4E8">    newchar </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> newchar.</span><span style="color: #B392F0">replace</span><span style="color: #E1E4E8">(</span><span style="color: #9ECBFF">&quot;零零&quot;</span><span style="color: #E1E4E8">, </span><span style="color: #9ECBFF">&quot;零&quot;</span><span style="color: #E1E4E8">);</span></span>
<span class="line"><span style="color: #E1E4E8">  newchar </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> newchar.</span><span style="color: #B392F0">replace</span><span style="color: #E1E4E8">(</span><span style="color: #9ECBFF">&quot;零亿&quot;</span><span style="color: #E1E4E8">, </span><span style="color: #9ECBFF">&quot;亿&quot;</span><span style="color: #E1E4E8">);</span></span>
<span class="line"><span style="color: #E1E4E8">  newchar </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> newchar.</span><span style="color: #B392F0">replace</span><span style="color: #E1E4E8">(</span><span style="color: #9ECBFF">&quot;亿万&quot;</span><span style="color: #E1E4E8">, </span><span style="color: #9ECBFF">&quot;亿&quot;</span><span style="color: #E1E4E8">);</span></span>
<span class="line"><span style="color: #E1E4E8">  newchar </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> newchar.</span><span style="color: #B392F0">replace</span><span style="color: #E1E4E8">(</span><span style="color: #9ECBFF">&quot;零万&quot;</span><span style="color: #E1E4E8">, </span><span style="color: #9ECBFF">&quot;万&quot;</span><span style="color: #E1E4E8">);</span></span>
<span class="line"><span style="color: #E1E4E8">  newchar </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> newchar.</span><span style="color: #B392F0">replace</span><span style="color: #E1E4E8">(</span><span style="color: #9ECBFF">&quot;零元&quot;</span><span style="color: #E1E4E8">, </span><span style="color: #9ECBFF">&quot;元&quot;</span><span style="color: #E1E4E8">);</span></span>
<span class="line"><span style="color: #E1E4E8">  newchar </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> newchar.</span><span style="color: #B392F0">replace</span><span style="color: #E1E4E8">(</span><span style="color: #9ECBFF">&quot;零角&quot;</span><span style="color: #E1E4E8">, </span><span style="color: #9ECBFF">&quot;&quot;</span><span style="color: #E1E4E8">);</span></span>
<span class="line"><span style="color: #E1E4E8">  newchar </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> newchar.</span><span style="color: #B392F0">replace</span><span style="color: #E1E4E8">(</span><span style="color: #9ECBFF">&quot;零分&quot;</span><span style="color: #E1E4E8">, </span><span style="color: #9ECBFF">&quot;&quot;</span><span style="color: #E1E4E8">);</span></span>
<span class="line"><span style="color: #E1E4E8">  </span><span style="color: #F97583">if</span><span style="color: #E1E4E8"> (newchar.</span><span style="color: #B392F0">charAt</span><span style="color: #E1E4E8">(newchar.</span><span style="color: #79B8FF">length</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">-</span><span style="color: #E1E4E8"> </span><span style="color: #79B8FF">1</span><span style="color: #E1E4E8">) </span><span style="color: #F97583">==</span><span style="color: #E1E4E8"> </span><span style="color: #9ECBFF">&quot;元&quot;</span><span style="color: #E1E4E8">) {</span></span>
<span class="line"><span style="color: #E1E4E8">    newchar </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> newchar </span><span style="color: #F97583">+</span><span style="color: #E1E4E8"> </span><span style="color: #9ECBFF">&quot;整&quot;</span></span>
<span class="line"><span style="color: #E1E4E8">  }</span></span>
<span class="line"><span style="color: #E1E4E8">  </span><span style="color: #F97583">return</span><span style="color: #E1E4E8"> newchar;</span></span>
<span class="line"><span style="color: #E1E4E8">}</span></span></code></pre></div></div></figure>

<h4 id="41-判断一个元素是否在数组中"><a href="#41-判断一个元素是否在数组中" class="headerlink" title="41.判断一个元素是否在数组中"></a>41.判断一个元素是否在数组中</h4><figure class="shiki javascript"><div class='codeblock'><div class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></div><div class="code"><pre class="shiki github-dark"><code><span class="line"><span style="color: #F97583">export</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">const</span><span style="color: #E1E4E8"> </span><span style="color: #B392F0">contains</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> (</span><span style="color: #FFAB70">arr</span><span style="color: #E1E4E8">, </span><span style="color: #FFAB70">val</span><span style="color: #E1E4E8">) </span><span style="color: #F97583">=&gt;</span><span style="color: #E1E4E8"> {</span></span>
<span class="line"><span style="color: #E1E4E8">    </span><span style="color: #F97583">return</span><span style="color: #E1E4E8"> arr.</span><span style="color: #B392F0">indexOf</span><span style="color: #E1E4E8">(val) </span><span style="color: #F97583">!=</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">-</span><span style="color: #79B8FF">1</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">?</span><span style="color: #E1E4E8"> </span><span style="color: #79B8FF">true</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">:</span><span style="color: #E1E4E8"> </span><span style="color: #79B8FF">false</span><span style="color: #E1E4E8">;</span></span>
<span class="line"><span style="color: #E1E4E8">}</span></span></code></pre></div></div></figure>

<h4 id="42-数组排序-type-1：从小到大-2：从大到小-3：随机"><a href="#42-数组排序-type-1：从小到大-2：从大到小-3：随机" class="headerlink" title="42.数组排序, {type} 1：从小到大 2：从大到小 3：随机"></a>42.数组排序, {type} 1：从小到大 2：从大到小 3：随机</h4><figure class="shiki javascript"><div class='codeblock'><div class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></div><div class="code"><pre class="shiki github-dark"><code><span class="line"><span style="color: #F97583">export</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">const</span><span style="color: #E1E4E8"> </span><span style="color: #B392F0">sort</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> (</span><span style="color: #FFAB70">arr</span><span style="color: #E1E4E8">, </span><span style="color: #FFAB70">type</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> </span><span style="color: #79B8FF">1</span><span style="color: #E1E4E8">) </span><span style="color: #F97583">=&gt;</span><span style="color: #E1E4E8"> {</span></span>
<span class="line"><span style="color: #E1E4E8">  </span><span style="color: #F97583">return</span><span style="color: #E1E4E8"> arr.</span><span style="color: #B392F0">sort</span><span style="color: #E1E4E8">((</span><span style="color: #FFAB70">a</span><span style="color: #E1E4E8">, </span><span style="color: #FFAB70">b</span><span style="color: #E1E4E8">) </span><span style="color: #F97583">=&gt;</span><span style="color: #E1E4E8"> {</span></span>
<span class="line"><span style="color: #E1E4E8">    </span><span style="color: #F97583">switch</span><span style="color: #E1E4E8"> (type) {</span></span>
<span class="line"><span style="color: #E1E4E8">    </span><span style="color: #F97583">case</span><span style="color: #E1E4E8"> </span><span style="color: #79B8FF">1</span><span style="color: #E1E4E8">:</span></span>
<span class="line"><span style="color: #E1E4E8">      </span><span style="color: #F97583">return</span><span style="color: #E1E4E8"> a </span><span style="color: #F97583">-</span><span style="color: #E1E4E8"> b;</span></span>
<span class="line"><span style="color: #E1E4E8">    </span><span style="color: #F97583">case</span><span style="color: #E1E4E8"> </span><span style="color: #79B8FF">2</span><span style="color: #E1E4E8">:</span></span>
<span class="line"><span style="color: #E1E4E8">      </span><span style="color: #F97583">return</span><span style="color: #E1E4E8"> b </span><span style="color: #F97583">-</span><span style="color: #E1E4E8"> a;</span></span>
<span class="line"><span style="color: #E1E4E8">    </span><span style="color: #F97583">case</span><span style="color: #E1E4E8"> </span><span style="color: #79B8FF">3</span><span style="color: #E1E4E8">:</span></span>
<span class="line"><span style="color: #E1E4E8">      </span><span style="color: #F97583">return</span><span style="color: #E1E4E8"> Math.</span><span style="color: #B392F0">random</span><span style="color: #E1E4E8">() </span><span style="color: #F97583">-</span><span style="color: #E1E4E8"> </span><span style="color: #79B8FF">0.5</span><span style="color: #E1E4E8">;</span></span>
<span class="line"><span style="color: #E1E4E8">    </span><span style="color: #F97583">default</span><span style="color: #E1E4E8">:</span></span>
<span class="line"><span style="color: #E1E4E8">      </span><span style="color: #F97583">return</span><span style="color: #E1E4E8"> arr;</span></span>
<span class="line"><span style="color: #E1E4E8">    }</span></span>
<span class="line"><span style="color: #E1E4E8">  })</span></span>
<span class="line"><span style="color: #E1E4E8">}</span></span></code></pre></div></div></figure>

<h4 id="43-数组去重"><a href="#43-数组去重" class="headerlink" title="43.数组去重"></a>43.数组去重</h4><figure class="shiki javascript"><div class='codeblock'><div class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></div><div class="code"><pre class="shiki github-dark"><code><span class="line"><span style="color: #F97583">export</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">const</span><span style="color: #E1E4E8"> </span><span style="color: #B392F0">unique</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> (</span><span style="color: #FFAB70">arr</span><span style="color: #E1E4E8">) </span><span style="color: #F97583">=&gt;</span><span style="color: #E1E4E8"> {</span></span>
<span class="line"><span style="color: #E1E4E8">  </span><span style="color: #F97583">if</span><span style="color: #E1E4E8"> (Array.</span><span style="color: #B392F0">hasOwnProperty</span><span style="color: #E1E4E8">(</span><span style="color: #9ECBFF">&#39;from&#39;</span><span style="color: #E1E4E8">)) {</span></span>
<span class="line"><span style="color: #E1E4E8">    </span><span style="color: #F97583">return</span><span style="color: #E1E4E8"> Array.</span><span style="color: #B392F0">from</span><span style="color: #E1E4E8">(</span><span style="color: #F97583">new</span><span style="color: #E1E4E8"> </span><span style="color: #B392F0">Set</span><span style="color: #E1E4E8">(arr));</span></span>
<span class="line"><span style="color: #E1E4E8">  } </span><span style="color: #F97583">else</span><span style="color: #E1E4E8"> {</span></span>
<span class="line"><span style="color: #E1E4E8">    </span><span style="color: #F97583">var</span><span style="color: #E1E4E8"> n </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> {}, r </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> [];</span></span>
<span class="line"><span style="color: #E1E4E8">    </span><span style="color: #F97583">for</span><span style="color: #E1E4E8"> (</span><span style="color: #F97583">var</span><span style="color: #E1E4E8"> i </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> </span><span style="color: #79B8FF">0</span><span style="color: #E1E4E8">; i </span><span style="color: #F97583">&lt;</span><span style="color: #E1E4E8"> arr.</span><span style="color: #79B8FF">length</span><span style="color: #E1E4E8">; i</span><span style="color: #F97583">++</span><span style="color: #E1E4E8">) {</span></span>
<span class="line"><span style="color: #E1E4E8">      </span><span style="color: #F97583">if</span><span style="color: #E1E4E8"> (</span><span style="color: #F97583">!</span><span style="color: #E1E4E8">n[arr[i]]) {</span></span>
<span class="line"><span style="color: #E1E4E8">        n[arr[i]] </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> </span><span style="color: #79B8FF">true</span><span style="color: #E1E4E8">;</span></span>
<span class="line"><span style="color: #E1E4E8">        r.</span><span style="color: #B392F0">push</span><span style="color: #E1E4E8">(arr[i]);</span></span>
<span class="line"><span style="color: #E1E4E8">      }</span></span>
<span class="line"><span style="color: #E1E4E8">    }</span></span>
<span class="line"><span style="color: #E1E4E8">    </span><span style="color: #F97583">return</span><span style="color: #E1E4E8"> r;</span></span>
<span class="line"><span style="color: #E1E4E8">  }</span></span>
<span class="line"><span style="color: #E1E4E8">}</span></span></code></pre></div></div></figure>

<h4 id="44-求两个集合的并集"><a href="#44-求两个集合的并集" class="headerlink" title="44.求两个集合的并集"></a>44.求两个集合的并集</h4><figure class="shiki javascript"><div class='codeblock'><div class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></div><div class="code"><pre class="shiki github-dark"><code><span class="line"><span style="color: #F97583">export</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">const</span><span style="color: #E1E4E8"> </span><span style="color: #B392F0">union</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> (</span><span style="color: #FFAB70">a</span><span style="color: #E1E4E8">, </span><span style="color: #FFAB70">b</span><span style="color: #E1E4E8">) </span><span style="color: #F97583">=&gt;</span><span style="color: #E1E4E8"> {</span></span>
<span class="line"><span style="color: #E1E4E8">  </span><span style="color: #F97583">var</span><span style="color: #E1E4E8"> newArr </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> a.</span><span style="color: #B392F0">concat</span><span style="color: #E1E4E8">(b);</span></span>
<span class="line"><span style="color: #E1E4E8">  </span><span style="color: #F97583">return</span><span style="color: #E1E4E8"> </span><span style="color: #79B8FF">this</span><span style="color: #E1E4E8">.</span><span style="color: #B392F0">unique</span><span style="color: #E1E4E8">(newArr); </span><span style="color: #6A737D">// 见43</span></span>
<span class="line"><span style="color: #E1E4E8">}</span></span></code></pre></div></div></figure>

<h4 id="45-求两个集合的交集"><a href="#45-求两个集合的交集" class="headerlink" title="45.求两个集合的交集"></a>45.求两个集合的交集</h4><figure class="shiki javascript"><div class='codeblock'><div class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></div><div class="code"><pre class="shiki github-dark"><code><span class="line"><span style="color: #F97583">export</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">const</span><span style="color: #E1E4E8"> </span><span style="color: #B392F0">intersect</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> (</span><span style="color: #FFAB70">a</span><span style="color: #E1E4E8">, </span><span style="color: #FFAB70">b</span><span style="color: #E1E4E8">) </span><span style="color: #F97583">=&gt;</span><span style="color: #E1E4E8"> {</span></span>
<span class="line"><span style="color: #E1E4E8">  </span><span style="color: #F97583">var</span><span style="color: #E1E4E8"> _this </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> </span><span style="color: #79B8FF">this</span><span style="color: #E1E4E8">;</span></span>
<span class="line"><span style="color: #E1E4E8">  a </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> </span><span style="color: #79B8FF">this</span><span style="color: #E1E4E8">.</span><span style="color: #B392F0">unique</span><span style="color: #E1E4E8">(a);</span></span>
<span class="line"><span style="color: #E1E4E8">  </span><span style="color: #F97583">return</span><span style="color: #E1E4E8"> </span><span style="color: #79B8FF">this</span><span style="color: #E1E4E8">.</span><span style="color: #B392F0">map</span><span style="color: #E1E4E8">(a, </span><span style="color: #F97583">function</span><span style="color: #E1E4E8"> (</span><span style="color: #FFAB70">o</span><span style="color: #E1E4E8">) {</span></span>
<span class="line"><span style="color: #E1E4E8">    </span><span style="color: #F97583">return</span><span style="color: #E1E4E8"> _this.</span><span style="color: #B392F0">contains</span><span style="color: #E1E4E8">(b, o) </span><span style="color: #F97583">?</span><span style="color: #E1E4E8"> o </span><span style="color: #F97583">:</span><span style="color: #E1E4E8"> </span><span style="color: #79B8FF">null</span><span style="color: #E1E4E8">; </span><span style="color: #6A737D">// contains方法见41</span></span>
<span class="line"><span style="color: #E1E4E8">  });</span></span>
<span class="line"><span style="color: #E1E4E8">}</span></span></code></pre></div></div></figure>

<h4 id="46-删除数组指定元素"><a href="#46-删除数组指定元素" class="headerlink" title="46.删除数组指定元素"></a>46.删除数组指定元素</h4><figure class="shiki javascript"><div class='codeblock'><div class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></div><div class="code"><pre class="shiki github-dark"><code><span class="line"><span style="color: #F97583">export</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">const</span><span style="color: #E1E4E8"> </span><span style="color: #B392F0">remove</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> (</span><span style="color: #FFAB70">arr</span><span style="color: #E1E4E8">, </span><span style="color: #FFAB70">ele</span><span style="color: #E1E4E8">) </span><span style="color: #F97583">=&gt;</span><span style="color: #E1E4E8"> {</span></span>
<span class="line"><span style="color: #E1E4E8">  </span><span style="color: #F97583">var</span><span style="color: #E1E4E8"> index </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> arr.</span><span style="color: #B392F0">indexOf</span><span style="color: #E1E4E8">(ele);</span></span>
<span class="line"><span style="color: #E1E4E8">  </span><span style="color: #F97583">if</span><span style="color: #E1E4E8"> (index </span><span style="color: #F97583">&gt;</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">-</span><span style="color: #79B8FF">1</span><span style="color: #E1E4E8">) {</span></span>
<span class="line"><span style="color: #E1E4E8">    arr.</span><span style="color: #B392F0">splice</span><span style="color: #E1E4E8">(index, </span><span style="color: #79B8FF">1</span><span style="color: #E1E4E8">);</span></span>
<span class="line"><span style="color: #E1E4E8">  }</span></span>
<span class="line"><span style="color: #E1E4E8">  </span><span style="color: #F97583">return</span><span style="color: #E1E4E8"> arr;</span></span>
<span class="line"><span style="color: #E1E4E8">}</span></span></code></pre></div></div></figure>

<h4 id="47-将类数组转换为数组"><a href="#47-将类数组转换为数组" class="headerlink" title="47.将类数组转换为数组"></a>47.将类数组转换为数组</h4><figure class="shiki javascript"><div class='codeblock'><div class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></div><div class="code"><pre class="shiki github-dark"><code><span class="line"><span style="color: #F97583">export</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">const</span><span style="color: #E1E4E8"> </span><span style="color: #B392F0">formArray</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> (</span><span style="color: #FFAB70">ary</span><span style="color: #E1E4E8">) </span><span style="color: #F97583">=&gt;</span><span style="color: #E1E4E8"> {</span></span>
<span class="line"><span style="color: #E1E4E8">  </span><span style="color: #F97583">var</span><span style="color: #E1E4E8"> arr </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> [];</span></span>
<span class="line"><span style="color: #E1E4E8">  </span><span style="color: #F97583">if</span><span style="color: #E1E4E8"> (Array.</span><span style="color: #B392F0">isArray</span><span style="color: #E1E4E8">(ary)) {</span></span>
<span class="line"><span style="color: #E1E4E8">    arr </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> ary;</span></span>
<span class="line"><span style="color: #E1E4E8">  } </span><span style="color: #F97583">else</span><span style="color: #E1E4E8"> {</span></span>
<span class="line"><span style="color: #E1E4E8">    arr </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> </span><span style="color: #79B8FF">Array</span><span style="color: #E1E4E8">.</span><span style="color: #79B8FF">prototype</span><span style="color: #E1E4E8">.slice.</span><span style="color: #B392F0">call</span><span style="color: #E1E4E8">(ary);</span></span>
<span class="line"><span style="color: #E1E4E8">  };</span></span>
<span class="line"><span style="color: #E1E4E8">  </span><span style="color: #F97583">return</span><span style="color: #E1E4E8"> arr;</span></span>
<span class="line"><span style="color: #E1E4E8">}</span></span></code></pre></div></div></figure>

<h4 id="48-找出数组最大值"><a href="#48-找出数组最大值" class="headerlink" title="48.找出数组最大值"></a>48.找出数组最大值</h4><figure class="shiki javascript"><div class='codeblock'><div class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></div><div class="code"><pre class="shiki github-dark"><code><span class="line"><span style="color: #F97583">export</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">const</span><span style="color: #E1E4E8"> </span><span style="color: #B392F0">max</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> (</span><span style="color: #FFAB70">arr</span><span style="color: #E1E4E8">) </span><span style="color: #F97583">=&gt;</span><span style="color: #E1E4E8"> {</span></span>
<span class="line"><span style="color: #E1E4E8">  </span><span style="color: #F97583">return</span><span style="color: #E1E4E8"> Math.max.</span><span style="color: #B392F0">apply</span><span style="color: #E1E4E8">(</span><span style="color: #79B8FF">null</span><span style="color: #E1E4E8">, arr);</span></span>
<span class="line"><span style="color: #E1E4E8">}</span></span></code></pre></div></div></figure>

<h4 id="49-找出数组最小值"><a href="#49-找出数组最小值" class="headerlink" title="49.找出数组最小值"></a>49.找出数组最小值</h4><figure class="shiki javascript"><div class='codeblock'><div class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></div><div class="code"><pre class="shiki github-dark"><code><span class="line"><span style="color: #F97583">export</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">const</span><span style="color: #E1E4E8"> </span><span style="color: #B392F0">min</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> (</span><span style="color: #FFAB70">arr</span><span style="color: #E1E4E8">) </span><span style="color: #F97583">=&gt;</span><span style="color: #E1E4E8"> {</span></span>
<span class="line"><span style="color: #E1E4E8">    </span><span style="color: #F97583">return</span><span style="color: #E1E4E8"> Math.min.</span><span style="color: #B392F0">apply</span><span style="color: #E1E4E8">(</span><span style="color: #79B8FF">null</span><span style="color: #E1E4E8">, arr);</span></span>
<span class="line"><span style="color: #E1E4E8">}</span></span></code></pre></div></div></figure>

<h4 id="50-数组求和"><a href="#50-数组求和" class="headerlink" title="50.数组求和"></a>50.数组求和</h4><figure class="shiki javascript"><div class='codeblock'><div class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></div><div class="code"><pre class="shiki github-dark"><code><span class="line"><span style="color: #F97583">export</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">const</span><span style="color: #E1E4E8"> </span><span style="color: #B392F0">sum</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> (</span><span style="color: #FFAB70">arr</span><span style="color: #E1E4E8">) </span><span style="color: #F97583">=&gt;</span><span style="color: #E1E4E8"> {</span></span>
<span class="line"><span style="color: #E1E4E8">    </span><span style="color: #F97583">return</span><span style="color: #E1E4E8"> arr.</span><span style="color: #B392F0">reduce</span><span style="color: #E1E4E8">((</span><span style="color: #FFAB70">pre</span><span style="color: #E1E4E8">, </span><span style="color: #FFAB70">cur</span><span style="color: #E1E4E8">) </span><span style="color: #F97583">=&gt;</span><span style="color: #E1E4E8"> {</span></span>
<span class="line"><span style="color: #E1E4E8">        </span><span style="color: #F97583">return</span><span style="color: #E1E4E8"> pre </span><span style="color: #F97583">+</span><span style="color: #E1E4E8"> cur</span></span>
<span class="line"><span style="color: #E1E4E8">    })</span></span>
<span class="line"><span style="color: #E1E4E8">}</span></span></code></pre></div></div></figure>

<h4 id="51-数组平均数"><a href="#51-数组平均数" class="headerlink" title="51.数组平均数"></a>51.数组平均数</h4><figure class="shiki javascript"><div class='codeblock'><div class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></div><div class="code"><pre class="shiki github-dark"><code><span class="line"><span style="color: #F97583">export</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">const</span><span style="color: #E1E4E8"> </span><span style="color: #B392F0">average</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> (</span><span style="color: #FFAB70">arr</span><span style="color: #E1E4E8">) </span><span style="color: #F97583">=&gt;</span><span style="color: #E1E4E8"> {</span></span>
<span class="line"><span style="color: #E1E4E8">    </span><span style="color: #F97583">return</span><span style="color: #E1E4E8"> </span><span style="color: #79B8FF">this</span><span style="color: #E1E4E8">.</span><span style="color: #B392F0">sum</span><span style="color: #E1E4E8">(arr) </span><span style="color: #F97583">/</span><span style="color: #E1E4E8"> arr.</span><span style="color: #79B8FF">length</span></span>
<span class="line"><span style="color: #E1E4E8">}</span></span></code></pre></div></div></figure>

<h4 id="52-去除空格-type-1-所有空格-2-前后空格-3-前空格-4-后空格"><a href="#52-去除空格-type-1-所有空格-2-前后空格-3-前空格-4-后空格" class="headerlink" title="52.去除空格,type: 1-所有空格 2-前后空格 3-前空格 4-后空格"></a>52.去除空格,<code>type: 1-所有空格 2-前后空格 3-前空格 4-后空格</code></h4><figure class="shiki javascript"><div class='codeblock'><div class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></div><div class="code"><pre class="shiki github-dark"><code><span class="line"><span style="color: #F97583">export</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">const</span><span style="color: #E1E4E8"> </span><span style="color: #B392F0">trim</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> (</span><span style="color: #FFAB70">str</span><span style="color: #E1E4E8">, </span><span style="color: #FFAB70">type</span><span style="color: #E1E4E8">) </span><span style="color: #F97583">=&gt;</span><span style="color: #E1E4E8"> {</span></span>
<span class="line"><span style="color: #E1E4E8">  type </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> type </span><span style="color: #F97583">||</span><span style="color: #E1E4E8"> </span><span style="color: #79B8FF">1</span></span>
<span class="line"><span style="color: #E1E4E8">  </span><span style="color: #F97583">switch</span><span style="color: #E1E4E8"> (type) {</span></span>
<span class="line"><span style="color: #E1E4E8">    </span><span style="color: #F97583">case</span><span style="color: #E1E4E8"> </span><span style="color: #79B8FF">1</span><span style="color: #E1E4E8">:</span></span>
<span class="line"><span style="color: #E1E4E8">      </span><span style="color: #F97583">return</span><span style="color: #E1E4E8"> str.</span><span style="color: #B392F0">replace</span><span style="color: #E1E4E8">(</span><span style="color: #9ECBFF">/</span><span style="color: #79B8FF">\s</span><span style="color: #F97583">+</span><span style="color: #9ECBFF">/</span><span style="color: #F97583">g</span><span style="color: #E1E4E8">, </span><span style="color: #9ECBFF">&quot;&quot;</span><span style="color: #E1E4E8">);</span></span>
<span class="line"><span style="color: #E1E4E8">    </span><span style="color: #F97583">case</span><span style="color: #E1E4E8"> </span><span style="color: #79B8FF">2</span><span style="color: #E1E4E8">:</span></span>
<span class="line"><span style="color: #E1E4E8">      </span><span style="color: #F97583">return</span><span style="color: #E1E4E8"> str.</span><span style="color: #B392F0">replace</span><span style="color: #E1E4E8">(</span><span style="color: #9ECBFF">/</span><span style="color: #DBEDFF">(</span><span style="color: #F97583">^</span><span style="color: #79B8FF">\s</span><span style="color: #F97583">*</span><span style="color: #DBEDFF">)</span><span style="color: #F97583">|</span><span style="color: #DBEDFF">(</span><span style="color: #79B8FF">\s</span><span style="color: #F97583">*$</span><span style="color: #DBEDFF">)</span><span style="color: #9ECBFF">/</span><span style="color: #F97583">g</span><span style="color: #E1E4E8">, </span><span style="color: #9ECBFF">&quot;&quot;</span><span style="color: #E1E4E8">);</span></span>
<span class="line"><span style="color: #E1E4E8">    </span><span style="color: #F97583">case</span><span style="color: #E1E4E8"> </span><span style="color: #79B8FF">3</span><span style="color: #E1E4E8">:</span></span>
<span class="line"><span style="color: #E1E4E8">      </span><span style="color: #F97583">return</span><span style="color: #E1E4E8"> str.</span><span style="color: #B392F0">replace</span><span style="color: #E1E4E8">(</span><span style="color: #9ECBFF">/</span><span style="color: #DBEDFF">(</span><span style="color: #F97583">^</span><span style="color: #79B8FF">\s</span><span style="color: #F97583">*</span><span style="color: #DBEDFF">)</span><span style="color: #9ECBFF">/</span><span style="color: #F97583">g</span><span style="color: #E1E4E8">, </span><span style="color: #9ECBFF">&quot;&quot;</span><span style="color: #E1E4E8">);</span></span>
<span class="line"><span style="color: #E1E4E8">    </span><span style="color: #F97583">case</span><span style="color: #E1E4E8"> </span><span style="color: #79B8FF">4</span><span style="color: #E1E4E8">:</span></span>
<span class="line"><span style="color: #E1E4E8">      </span><span style="color: #F97583">return</span><span style="color: #E1E4E8"> str.</span><span style="color: #B392F0">replace</span><span style="color: #E1E4E8">(</span><span style="color: #9ECBFF">/</span><span style="color: #DBEDFF">(</span><span style="color: #79B8FF">\s</span><span style="color: #F97583">*$</span><span style="color: #DBEDFF">)</span><span style="color: #9ECBFF">/</span><span style="color: #F97583">g</span><span style="color: #E1E4E8">, </span><span style="color: #9ECBFF">&quot;&quot;</span><span style="color: #E1E4E8">);</span></span>
<span class="line"><span style="color: #E1E4E8">    </span><span style="color: #F97583">default</span><span style="color: #E1E4E8">:</span></span>
<span class="line"><span style="color: #E1E4E8">      </span><span style="color: #F97583">return</span><span style="color: #E1E4E8"> str;</span></span>
<span class="line"><span style="color: #E1E4E8">  }</span></span>
<span class="line"><span style="color: #E1E4E8">}</span></span></code></pre></div></div></figure>

<h4 id="53-字符转换-type-1-首字母大写-2：首字母小写-3：大小写转换-4：全部大写-5：全部小写"><a href="#53-字符转换-type-1-首字母大写-2：首字母小写-3：大小写转换-4：全部大写-5：全部小写" class="headerlink" title="53.字符转换,type: 1:首字母大写 2：首字母小写 3：大小写转换 4：全部大写 5：全部小写"></a>53.字符转换,type: 1:首字母大写 2：首字母小写 3：大小写转换 4：全部大写 5：全部小写</h4><figure class="shiki javascript"><div class='codeblock'><div class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br></pre></div><div class="code"><pre class="shiki github-dark"><code><span class="line"><span style="color: #F97583">export</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">const</span><span style="color: #E1E4E8"> </span><span style="color: #B392F0">changeCase</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> (</span><span style="color: #FFAB70">str</span><span style="color: #E1E4E8">, </span><span style="color: #FFAB70">type</span><span style="color: #E1E4E8">) </span><span style="color: #F97583">=&gt;</span><span style="color: #E1E4E8"> {</span></span>
<span class="line"><span style="color: #E1E4E8">  type </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> type </span><span style="color: #F97583">||</span><span style="color: #E1E4E8"> </span><span style="color: #79B8FF">4</span></span>
<span class="line"><span style="color: #E1E4E8">  </span><span style="color: #F97583">switch</span><span style="color: #E1E4E8"> (type) {</span></span>
<span class="line"><span style="color: #E1E4E8">    </span><span style="color: #F97583">case</span><span style="color: #E1E4E8"> </span><span style="color: #79B8FF">1</span><span style="color: #E1E4E8">:</span></span>
<span class="line"><span style="color: #E1E4E8">      </span><span style="color: #F97583">return</span><span style="color: #E1E4E8"> str.</span><span style="color: #B392F0">replace</span><span style="color: #E1E4E8">(</span><span style="color: #9ECBFF">/</span><span style="color: #F97583">\b</span><span style="color: #79B8FF">\w</span><span style="color: #F97583">+\b</span><span style="color: #9ECBFF">/</span><span style="color: #F97583">g</span><span style="color: #E1E4E8">, </span><span style="color: #F97583">function</span><span style="color: #E1E4E8"> (</span><span style="color: #FFAB70">word</span><span style="color: #E1E4E8">) {</span></span>
<span class="line"><span style="color: #E1E4E8">        </span><span style="color: #F97583">return</span><span style="color: #E1E4E8"> word.</span><span style="color: #B392F0">substring</span><span style="color: #E1E4E8">(</span><span style="color: #79B8FF">0</span><span style="color: #E1E4E8">, </span><span style="color: #79B8FF">1</span><span style="color: #E1E4E8">).</span><span style="color: #B392F0">toUpperCase</span><span style="color: #E1E4E8">() </span><span style="color: #F97583">+</span><span style="color: #E1E4E8"> word.</span><span style="color: #B392F0">substring</span><span style="color: #E1E4E8">(</span><span style="color: #79B8FF">1</span><span style="color: #E1E4E8">).</span><span style="color: #B392F0">toLowerCase</span><span style="color: #E1E4E8">();</span></span>
<span class="line"></span>
<span class="line"><span style="color: #E1E4E8">      });</span></span>
<span class="line"><span style="color: #E1E4E8">    </span><span style="color: #F97583">case</span><span style="color: #E1E4E8"> </span><span style="color: #79B8FF">2</span><span style="color: #E1E4E8">:</span></span>
<span class="line"><span style="color: #E1E4E8">      </span><span style="color: #F97583">return</span><span style="color: #E1E4E8"> str.</span><span style="color: #B392F0">replace</span><span style="color: #E1E4E8">(</span><span style="color: #9ECBFF">/</span><span style="color: #F97583">\b</span><span style="color: #79B8FF">\w</span><span style="color: #F97583">+\b</span><span style="color: #9ECBFF">/</span><span style="color: #F97583">g</span><span style="color: #E1E4E8">, </span><span style="color: #F97583">function</span><span style="color: #E1E4E8"> (</span><span style="color: #FFAB70">word</span><span style="color: #E1E4E8">) {</span></span>
<span class="line"><span style="color: #E1E4E8">        </span><span style="color: #F97583">return</span><span style="color: #E1E4E8"> word.</span><span style="color: #B392F0">substring</span><span style="color: #E1E4E8">(</span><span style="color: #79B8FF">0</span><span style="color: #E1E4E8">, </span><span style="color: #79B8FF">1</span><span style="color: #E1E4E8">).</span><span style="color: #B392F0">toLowerCase</span><span style="color: #E1E4E8">() </span><span style="color: #F97583">+</span><span style="color: #E1E4E8"> word.</span><span style="color: #B392F0">substring</span><span style="color: #E1E4E8">(</span><span style="color: #79B8FF">1</span><span style="color: #E1E4E8">).</span><span style="color: #B392F0">toUpperCase</span><span style="color: #E1E4E8">();</span></span>
<span class="line"><span style="color: #E1E4E8">      });</span></span>
<span class="line"><span style="color: #E1E4E8">    </span><span style="color: #F97583">case</span><span style="color: #E1E4E8"> </span><span style="color: #79B8FF">3</span><span style="color: #E1E4E8">:</span></span>
<span class="line"><span style="color: #E1E4E8">      </span><span style="color: #F97583">return</span><span style="color: #E1E4E8"> str.</span><span style="color: #B392F0">split</span><span style="color: #E1E4E8">(</span><span style="color: #9ECBFF">&#39;&#39;</span><span style="color: #E1E4E8">).</span><span style="color: #B392F0">map</span><span style="color: #E1E4E8">(</span><span style="color: #F97583">function</span><span style="color: #E1E4E8"> (</span><span style="color: #FFAB70">word</span><span style="color: #E1E4E8">) {</span></span>
<span class="line"><span style="color: #E1E4E8">        </span><span style="color: #F97583">if</span><span style="color: #E1E4E8"> (</span><span style="color: #9ECBFF">/</span><span style="color: #79B8FF">[a-z]</span><span style="color: #9ECBFF">/</span><span style="color: #E1E4E8">.</span><span style="color: #B392F0">test</span><span style="color: #E1E4E8">(word)) {</span></span>
<span class="line"><span style="color: #E1E4E8">          </span><span style="color: #F97583">return</span><span style="color: #E1E4E8"> word.</span><span style="color: #B392F0">toUpperCase</span><span style="color: #E1E4E8">();</span></span>
<span class="line"><span style="color: #E1E4E8">        } </span><span style="color: #F97583">else</span><span style="color: #E1E4E8"> {</span></span>
<span class="line"><span style="color: #E1E4E8">          </span><span style="color: #F97583">return</span><span style="color: #E1E4E8"> word.</span><span style="color: #B392F0">toLowerCase</span><span style="color: #E1E4E8">()</span></span>
<span class="line"><span style="color: #E1E4E8">        }</span></span>
<span class="line"><span style="color: #E1E4E8">      }).</span><span style="color: #B392F0">join</span><span style="color: #E1E4E8">(</span><span style="color: #9ECBFF">&#39;&#39;</span><span style="color: #E1E4E8">)</span></span>
<span class="line"><span style="color: #E1E4E8">    </span><span style="color: #F97583">case</span><span style="color: #E1E4E8"> </span><span style="color: #79B8FF">4</span><span style="color: #E1E4E8">:</span></span>
<span class="line"><span style="color: #E1E4E8">      </span><span style="color: #F97583">return</span><span style="color: #E1E4E8"> str.</span><span style="color: #B392F0">toUpperCase</span><span style="color: #E1E4E8">();</span></span>
<span class="line"><span style="color: #E1E4E8">    </span><span style="color: #F97583">case</span><span style="color: #E1E4E8"> </span><span style="color: #79B8FF">5</span><span style="color: #E1E4E8">:</span></span>
<span class="line"><span style="color: #E1E4E8">      </span><span style="color: #F97583">return</span><span style="color: #E1E4E8"> str.</span><span style="color: #B392F0">toLowerCase</span><span style="color: #E1E4E8">();</span></span>
<span class="line"><span style="color: #E1E4E8">    </span><span style="color: #F97583">default</span><span style="color: #E1E4E8">:</span></span>
<span class="line"><span style="color: #E1E4E8">      </span><span style="color: #F97583">return</span><span style="color: #E1E4E8"> str;</span></span>
<span class="line"><span style="color: #E1E4E8">  }</span></span>
<span class="line"><span style="color: #E1E4E8">}</span></span></code></pre></div></div></figure>

<h4 id="54-检测密码强度"><a href="#54-检测密码强度" class="headerlink" title="54.检测密码强度"></a>54.检测密码强度</h4><figure class="shiki javascript"><div class='codeblock'><div class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br></pre></div><div class="code"><pre class="shiki github-dark"><code><span class="line"><span style="color: #F97583">export</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">const</span><span style="color: #E1E4E8"> </span><span style="color: #B392F0">checkPwd</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> (</span><span style="color: #FFAB70">str</span><span style="color: #E1E4E8">) </span><span style="color: #F97583">=&gt;</span><span style="color: #E1E4E8"> {</span></span>
<span class="line"><span style="color: #E1E4E8">  </span><span style="color: #F97583">var</span><span style="color: #E1E4E8"> Lv </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> </span><span style="color: #79B8FF">0</span><span style="color: #E1E4E8">;</span></span>
<span class="line"><span style="color: #E1E4E8">  </span><span style="color: #F97583">if</span><span style="color: #E1E4E8"> (str.</span><span style="color: #79B8FF">length</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">&lt;</span><span style="color: #E1E4E8"> </span><span style="color: #79B8FF">6</span><span style="color: #E1E4E8">) {</span></span>
<span class="line"><span style="color: #E1E4E8">    </span><span style="color: #F97583">return</span><span style="color: #E1E4E8"> Lv</span></span>
<span class="line"><span style="color: #E1E4E8">  }</span></span>
<span class="line"><span style="color: #E1E4E8">  </span><span style="color: #F97583">if</span><span style="color: #E1E4E8"> (</span><span style="color: #9ECBFF">/</span><span style="color: #79B8FF">[0-9]</span><span style="color: #9ECBFF">/</span><span style="color: #E1E4E8">.</span><span style="color: #B392F0">test</span><span style="color: #E1E4E8">(str)) {</span></span>
<span class="line"><span style="color: #E1E4E8">    Lv</span><span style="color: #F97583">++</span></span>
<span class="line"><span style="color: #E1E4E8">  }</span></span>
<span class="line"><span style="color: #E1E4E8">  </span><span style="color: #F97583">if</span><span style="color: #E1E4E8"> (</span><span style="color: #9ECBFF">/</span><span style="color: #79B8FF">[a-z]</span><span style="color: #9ECBFF">/</span><span style="color: #E1E4E8">.</span><span style="color: #B392F0">test</span><span style="color: #E1E4E8">(str)) {</span></span>
<span class="line"><span style="color: #E1E4E8">    Lv</span><span style="color: #F97583">++</span></span>
<span class="line"><span style="color: #E1E4E8">  }</span></span>
<span class="line"><span style="color: #E1E4E8">  </span><span style="color: #F97583">if</span><span style="color: #E1E4E8"> (</span><span style="color: #9ECBFF">/</span><span style="color: #79B8FF">[A-Z]</span><span style="color: #9ECBFF">/</span><span style="color: #E1E4E8">.</span><span style="color: #B392F0">test</span><span style="color: #E1E4E8">(str)) {</span></span>
<span class="line"><span style="color: #E1E4E8">    Lv</span><span style="color: #F97583">++</span></span>
<span class="line"><span style="color: #E1E4E8">  }</span></span>
<span class="line"><span style="color: #E1E4E8">  </span><span style="color: #F97583">if</span><span style="color: #E1E4E8"> (</span><span style="color: #9ECBFF">/</span><span style="color: #79B8FF">[</span><span style="color: #85E89D; font-weight: bold">\.</span><span style="color: #79B8FF">|-|_]</span><span style="color: #9ECBFF">/</span><span style="color: #E1E4E8">.</span><span style="color: #B392F0">test</span><span style="color: #E1E4E8">(str)) {</span></span>
<span class="line"><span style="color: #E1E4E8">    Lv</span><span style="color: #F97583">++</span></span>
<span class="line"><span style="color: #E1E4E8">  }</span></span>
<span class="line"><span style="color: #E1E4E8">  </span><span style="color: #F97583">return</span><span style="color: #E1E4E8"> Lv;</span></span>
<span class="line"><span style="color: #E1E4E8">}</span></span></code></pre></div></div></figure>

<h4 id="55-函数节流器"><a href="#55-函数节流器" class="headerlink" title="55.函数节流器"></a>55.函数节流器</h4><figure class="shiki javascript"><div class='codeblock'><div class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></div><div class="code"><pre class="shiki github-dark"><code><span class="line"><span style="color: #F97583">export</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">const</span><span style="color: #E1E4E8"> </span><span style="color: #B392F0">debouncer</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> (</span><span style="color: #FFAB70">fn</span><span style="color: #E1E4E8">, </span><span style="color: #FFAB70">time</span><span style="color: #E1E4E8">, </span><span style="color: #FFAB70">interval</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> </span><span style="color: #79B8FF">200</span><span style="color: #E1E4E8">) </span><span style="color: #F97583">=&gt;</span><span style="color: #E1E4E8"> {</span></span>
<span class="line"><span style="color: #E1E4E8">  </span><span style="color: #F97583">if</span><span style="color: #E1E4E8"> (time </span><span style="color: #F97583">-</span><span style="color: #E1E4E8"> (window.debounceTimestamp </span><span style="color: #F97583">||</span><span style="color: #E1E4E8"> </span><span style="color: #79B8FF">0</span><span style="color: #E1E4E8">) </span><span style="color: #F97583">&gt;</span><span style="color: #E1E4E8"> interval) {</span></span>
<span class="line"><span style="color: #E1E4E8">    fn </span><span style="color: #F97583">&amp;&amp;</span><span style="color: #E1E4E8"> </span><span style="color: #B392F0">fn</span><span style="color: #E1E4E8">();</span></span>
<span class="line"><span style="color: #E1E4E8">    window.debounceTimestamp </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> time;</span></span>
<span class="line"><span style="color: #E1E4E8">  }</span></span>
<span class="line"><span style="color: #E1E4E8">}</span></span></code></pre></div></div></figure>

<h4 id="56-在字符串中插入新字符串"><a href="#56-在字符串中插入新字符串" class="headerlink" title="56.在字符串中插入新字符串"></a>56.在字符串中插入新字符串</h4><figure class="shiki javascript"><div class='codeblock'><div class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></div><div class="code"><pre class="shiki github-dark"><code><span class="line"><span style="color: #F97583">export</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">const</span><span style="color: #E1E4E8"> </span><span style="color: #B392F0">insertStr</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> (</span><span style="color: #FFAB70">soure</span><span style="color: #E1E4E8">, </span><span style="color: #FFAB70">index</span><span style="color: #E1E4E8">, </span><span style="color: #FFAB70">newStr</span><span style="color: #E1E4E8">) </span><span style="color: #F97583">=&gt;</span><span style="color: #E1E4E8"> {</span></span>
<span class="line"><span style="color: #E1E4E8">  </span><span style="color: #F97583">var</span><span style="color: #E1E4E8"> str </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> soure.</span><span style="color: #B392F0">slice</span><span style="color: #E1E4E8">(</span><span style="color: #79B8FF">0</span><span style="color: #E1E4E8">, index) </span><span style="color: #F97583">+</span><span style="color: #E1E4E8"> newStr </span><span style="color: #F97583">+</span><span style="color: #E1E4E8"> soure.</span><span style="color: #B392F0">slice</span><span style="color: #E1E4E8">(index);</span></span>
<span class="line"><span style="color: #E1E4E8">  </span><span style="color: #F97583">return</span><span style="color: #E1E4E8"> str;</span></span>
<span class="line"><span style="color: #E1E4E8">}</span></span></code></pre></div></div></figure>

<h4 id="57-判断两个对象是否键值相同"><a href="#57-判断两个对象是否键值相同" class="headerlink" title="57.判断两个对象是否键值相同"></a>57.判断两个对象是否键值相同</h4><figure class="shiki javascript"><div class='codeblock'><div class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></div><div class="code"><pre class="shiki github-dark"><code><span class="line"><span style="color: #F97583">export</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">const</span><span style="color: #E1E4E8"> </span><span style="color: #B392F0">isObjectEqual</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> (</span><span style="color: #FFAB70">a</span><span style="color: #E1E4E8">, </span><span style="color: #FFAB70">b</span><span style="color: #E1E4E8">) </span><span style="color: #F97583">=&gt;</span><span style="color: #E1E4E8"> {</span></span>
<span class="line"><span style="color: #E1E4E8">  </span><span style="color: #F97583">var</span><span style="color: #E1E4E8"> aProps </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> Object.</span><span style="color: #B392F0">getOwnPropertyNames</span><span style="color: #E1E4E8">(a);</span></span>
<span class="line"><span style="color: #E1E4E8">  </span><span style="color: #F97583">var</span><span style="color: #E1E4E8"> bProps </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> Object.</span><span style="color: #B392F0">getOwnPropertyNames</span><span style="color: #E1E4E8">(b);</span></span>
<span class="line"></span>
<span class="line"><span style="color: #E1E4E8">  </span><span style="color: #F97583">if</span><span style="color: #E1E4E8"> (aProps.</span><span style="color: #79B8FF">length</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">!==</span><span style="color: #E1E4E8"> bProps.</span><span style="color: #79B8FF">length</span><span style="color: #E1E4E8">) {</span></span>
<span class="line"><span style="color: #E1E4E8">    </span><span style="color: #F97583">return</span><span style="color: #E1E4E8"> </span><span style="color: #79B8FF">false</span><span style="color: #E1E4E8">;</span></span>
<span class="line"><span style="color: #E1E4E8">  }</span></span>
<span class="line"></span>
<span class="line"><span style="color: #E1E4E8">  </span><span style="color: #F97583">for</span><span style="color: #E1E4E8"> (</span><span style="color: #F97583">var</span><span style="color: #E1E4E8"> i </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> </span><span style="color: #79B8FF">0</span><span style="color: #E1E4E8">; i </span><span style="color: #F97583">&lt;</span><span style="color: #E1E4E8"> aProps.</span><span style="color: #79B8FF">length</span><span style="color: #E1E4E8">; i</span><span style="color: #F97583">++</span><span style="color: #E1E4E8">) {</span></span>
<span class="line"><span style="color: #E1E4E8">    </span><span style="color: #F97583">var</span><span style="color: #E1E4E8"> propName </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> aProps[i];</span></span>
<span class="line"></span>
<span class="line"><span style="color: #E1E4E8">    </span><span style="color: #F97583">if</span><span style="color: #E1E4E8"> (a[propName] </span><span style="color: #F97583">!==</span><span style="color: #E1E4E8"> b[propName]) {</span></span>
<span class="line"><span style="color: #E1E4E8">      </span><span style="color: #F97583">return</span><span style="color: #E1E4E8"> </span><span style="color: #79B8FF">false</span><span style="color: #E1E4E8">;</span></span>
<span class="line"><span style="color: #E1E4E8">    }</span></span>
<span class="line"><span style="color: #E1E4E8">  }</span></span>
<span class="line"><span style="color: #E1E4E8">  </span><span style="color: #F97583">return</span><span style="color: #E1E4E8"> </span><span style="color: #79B8FF">true</span><span style="color: #E1E4E8">;</span></span>
<span class="line"><span style="color: #E1E4E8">}</span></span></code></pre></div></div></figure>

<h4 id="58-16进制颜色转RGBRGBA字符串"><a href="#58-16进制颜色转RGBRGBA字符串" class="headerlink" title="58.16进制颜色转RGBRGBA字符串"></a>58.16进制颜色转RGBRGBA字符串</h4><figure class="shiki javascript"><div class='codeblock'><div class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br></pre></div><div class="code"><pre class="shiki github-dark"><code><span class="line"><span style="color: #F97583">export</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">const</span><span style="color: #E1E4E8"> </span><span style="color: #B392F0">colorToRGB</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> (</span><span style="color: #FFAB70">val</span><span style="color: #E1E4E8">, </span><span style="color: #FFAB70">opa</span><span style="color: #E1E4E8">) </span><span style="color: #F97583">=&gt;</span><span style="color: #E1E4E8"> {</span></span>
<span class="line"></span>
<span class="line"><span style="color: #E1E4E8">  </span><span style="color: #F97583">var</span><span style="color: #E1E4E8"> pattern </span><span style="color: #F97583">=</span><span style="color: #DBEDFF"> </span><span style="color: #9ECBFF">/</span><span style="color: #F97583">^</span><span style="color: #DBEDFF">(#</span><span style="color: #F97583">?</span><span style="color: #DBEDFF">)</span><span style="color: #79B8FF">[a-fA-F0-9]</span><span style="color: #F97583">{6}$</span><span style="color: #9ECBFF">/</span><span style="color: #E1E4E8">; </span><span style="color: #6A737D">//16进制颜色值校验规则</span></span>
<span class="line"><span style="color: #E1E4E8">  </span><span style="color: #F97583">var</span><span style="color: #E1E4E8"> isOpa </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">typeof</span><span style="color: #E1E4E8"> opa </span><span style="color: #F97583">==</span><span style="color: #E1E4E8"> </span><span style="color: #9ECBFF">&#39;number&#39;</span><span style="color: #E1E4E8">; </span><span style="color: #6A737D">//判断是否有设置不透明度</span></span>
<span class="line"></span>
<span class="line"><span style="color: #E1E4E8">  </span><span style="color: #F97583">if</span><span style="color: #E1E4E8"> (</span><span style="color: #F97583">!</span><span style="color: #E1E4E8">pattern.</span><span style="color: #B392F0">test</span><span style="color: #E1E4E8">(val)) { </span><span style="color: #6A737D">//如果值不符合规则返回空字符</span></span>
<span class="line"><span style="color: #E1E4E8">    </span><span style="color: #F97583">return</span><span style="color: #E1E4E8"> </span><span style="color: #9ECBFF">&#39;&#39;</span><span style="color: #E1E4E8">;</span></span>
<span class="line"><span style="color: #E1E4E8">  }</span></span>
<span class="line"></span>
<span class="line"><span style="color: #E1E4E8">  </span><span style="color: #F97583">var</span><span style="color: #E1E4E8"> v </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> val.</span><span style="color: #B392F0">replace</span><span style="color: #E1E4E8">(</span><span style="color: #9ECBFF">/</span><span style="color: #DBEDFF">#</span><span style="color: #9ECBFF">/</span><span style="color: #E1E4E8">, </span><span style="color: #9ECBFF">&#39;&#39;</span><span style="color: #E1E4E8">); </span><span style="color: #6A737D">//如果有#号先去除#号</span></span>
<span class="line"><span style="color: #E1E4E8">  </span><span style="color: #F97583">var</span><span style="color: #E1E4E8"> rgbArr </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> [];</span></span>
<span class="line"><span style="color: #E1E4E8">  </span><span style="color: #F97583">var</span><span style="color: #E1E4E8"> rgbStr </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> </span><span style="color: #9ECBFF">&#39;&#39;</span><span style="color: #E1E4E8">;</span></span>
<span class="line"></span>
<span class="line"><span style="color: #E1E4E8">  </span><span style="color: #F97583">for</span><span style="color: #E1E4E8"> (</span><span style="color: #F97583">var</span><span style="color: #E1E4E8"> i </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> </span><span style="color: #79B8FF">0</span><span style="color: #E1E4E8">; i </span><span style="color: #F97583">&lt;</span><span style="color: #E1E4E8"> </span><span style="color: #79B8FF">3</span><span style="color: #E1E4E8">; i</span><span style="color: #F97583">++</span><span style="color: #E1E4E8">) {</span></span>
<span class="line"><span style="color: #E1E4E8">    </span><span style="color: #F97583">var</span><span style="color: #E1E4E8"> item </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> v.</span><span style="color: #B392F0">substring</span><span style="color: #E1E4E8">(i </span><span style="color: #F97583">*</span><span style="color: #E1E4E8"> </span><span style="color: #79B8FF">2</span><span style="color: #E1E4E8">, i </span><span style="color: #F97583">*</span><span style="color: #E1E4E8"> </span><span style="color: #79B8FF">2</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">+</span><span style="color: #E1E4E8"> </span><span style="color: #79B8FF">2</span><span style="color: #E1E4E8">);</span></span>
<span class="line"><span style="color: #E1E4E8">    </span><span style="color: #F97583">var</span><span style="color: #E1E4E8"> num </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> </span><span style="color: #B392F0">parseInt</span><span style="color: #E1E4E8">(item, </span><span style="color: #79B8FF">16</span><span style="color: #E1E4E8">);</span></span>
<span class="line"><span style="color: #E1E4E8">    rgbArr.</span><span style="color: #B392F0">push</span><span style="color: #E1E4E8">(num);</span></span>
<span class="line"><span style="color: #E1E4E8">  }</span></span>
<span class="line"></span>
<span class="line"><span style="color: #E1E4E8">  rgbStr </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> rgbArr.</span><span style="color: #B392F0">join</span><span style="color: #E1E4E8">();</span></span>
<span class="line"><span style="color: #E1E4E8">  rgbStr </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> </span><span style="color: #9ECBFF">&#39;rgb&#39;</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">+</span><span style="color: #E1E4E8"> (isOpa </span><span style="color: #F97583">?</span><span style="color: #E1E4E8"> </span><span style="color: #9ECBFF">&#39;a&#39;</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">:</span><span style="color: #E1E4E8"> </span><span style="color: #9ECBFF">&#39;&#39;</span><span style="color: #E1E4E8">) </span><span style="color: #F97583">+</span><span style="color: #E1E4E8"> </span><span style="color: #9ECBFF">&#39;(&#39;</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">+</span><span style="color: #E1E4E8"> rgbStr </span><span style="color: #F97583">+</span><span style="color: #E1E4E8"> (isOpa </span><span style="color: #F97583">?</span><span style="color: #E1E4E8"> </span><span style="color: #9ECBFF">&#39;,&#39;</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">+</span><span style="color: #E1E4E8"> opa </span><span style="color: #F97583">:</span><span style="color: #E1E4E8"> </span><span style="color: #9ECBFF">&#39;&#39;</span><span style="color: #E1E4E8">) </span><span style="color: #F97583">+</span><span style="color: #E1E4E8"> </span><span style="color: #9ECBFF">&#39;)&#39;</span><span style="color: #E1E4E8">;</span></span>
<span class="line"><span style="color: #E1E4E8">  </span><span style="color: #F97583">return</span><span style="color: #E1E4E8"> rgbStr;</span></span>
<span class="line"><span style="color: #E1E4E8">}</span></span></code></pre></div></div></figure>

<h4 id="59-追加url参数"><a href="#59-追加url参数" class="headerlink" title="59.追加url参数"></a>59.追加url参数</h4><figure class="shiki javascript"><div class='codeblock'><div class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></div><div class="code"><pre class="shiki github-dark"><code><span class="line"><span style="color: #F97583">export</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">const</span><span style="color: #E1E4E8"> </span><span style="color: #B392F0">appendQuery</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> (</span><span style="color: #FFAB70">url</span><span style="color: #E1E4E8">, </span><span style="color: #FFAB70">key</span><span style="color: #E1E4E8">, </span><span style="color: #FFAB70">value</span><span style="color: #E1E4E8">) </span><span style="color: #F97583">=&gt;</span><span style="color: #E1E4E8"> {</span></span>
<span class="line"><span style="color: #E1E4E8">  </span><span style="color: #F97583">var</span><span style="color: #E1E4E8"> options </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> key;</span></span>
<span class="line"><span style="color: #E1E4E8">  </span><span style="color: #F97583">if</span><span style="color: #E1E4E8"> (</span><span style="color: #F97583">typeof</span><span style="color: #E1E4E8"> options </span><span style="color: #F97583">==</span><span style="color: #E1E4E8"> </span><span style="color: #9ECBFF">&#39;string&#39;</span><span style="color: #E1E4E8">) {</span></span>
<span class="line"><span style="color: #E1E4E8">    options </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> {};</span></span>
<span class="line"><span style="color: #E1E4E8">    options[key] </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> value;</span></span>
<span class="line"><span style="color: #E1E4E8">  }</span></span>
<span class="line"><span style="color: #E1E4E8">  options </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> $.</span><span style="color: #B392F0">param</span><span style="color: #E1E4E8">(options);</span></span>
<span class="line"><span style="color: #E1E4E8">  </span><span style="color: #F97583">if</span><span style="color: #E1E4E8"> (url.</span><span style="color: #B392F0">includes</span><span style="color: #E1E4E8">(</span><span style="color: #9ECBFF">&#39;?&#39;</span><span style="color: #E1E4E8">)) {</span></span>
<span class="line"><span style="color: #E1E4E8">    url </span><span style="color: #F97583">+=</span><span style="color: #E1E4E8"> </span><span style="color: #9ECBFF">&#39;&amp;&#39;</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">+</span><span style="color: #E1E4E8"> options</span></span>
<span class="line"><span style="color: #E1E4E8">  } </span><span style="color: #F97583">else</span><span style="color: #E1E4E8"> {</span></span>
<span class="line"><span style="color: #E1E4E8">    url </span><span style="color: #F97583">+=</span><span style="color: #E1E4E8"> </span><span style="color: #9ECBFF">&#39;?&#39;</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">+</span><span style="color: #E1E4E8"> options</span></span>
<span class="line"><span style="color: #E1E4E8">  }</span></span>
<span class="line"><span style="color: #E1E4E8">  </span><span style="color: #F97583">return</span><span style="color: #E1E4E8"> url;</span></span>
<span class="line"><span style="color: #E1E4E8">}</span></span></code></pre></div></div></figure>

    
  </article>

  
      
    <div class="nexmoe-post-copyright">
        <strong>本文作者：</strong>tangyuxian<br>
        
        <strong>本文链接：</strong><a href="https://www.tangyuxian.com/2021/04/08/%E5%89%8D%E7%AB%AF/JavaScript/js-%E5%B8%B8%E7%94%A8%E7%9A%84js%E5%B7%A5%E5%85%B7%E5%87%BD%E6%95%B0/" title="https:&#x2F;&#x2F;www.tangyuxian.com&#x2F;2021&#x2F;04&#x2F;08&#x2F;%E5%89%8D%E7%AB%AF&#x2F;JavaScript&#x2F;js-%E5%B8%B8%E7%94%A8%E7%9A%84js%E5%B7%A5%E5%85%B7%E5%87%BD%E6%95%B0&#x2F;" target="_blank" rel="noopener">https:&#x2F;&#x2F;www.tangyuxian.com&#x2F;2021&#x2F;04&#x2F;08&#x2F;%E5%89%8D%E7%AB%AF&#x2F;JavaScript&#x2F;js-%E5%B8%B8%E7%94%A8%E7%9A%84js%E5%B7%A5%E5%85%B7%E5%87%BD%E6%95%B0&#x2F;</a><br>

        
            <strong>版权声明：</strong>本文采用 <a href="https://creativecommons.org/licenses/by-nc-sa/3.0/cn/deed.zh" target="_blank">CC BY-NC-SA 3.0 CN</a> 协议进行许可

        
    </div>


  
  
  <div class="nexmoe-post-meta nexmoe-rainbow">
   
    
        <a class="nexmoefont icon-tag-fill -none-link" href="/tags/JavaScript/" rel="tag">JavaScript</a> <a class="nexmoefont icon-tag-fill -none-link" href="/tags/%E5%B7%A5%E5%85%B7/" rel="tag">工具</a>
    
</div>
  
  
    <script async src="/js/copy-codeblock.js?v=1763992123962"></script>
  

  
      <div class="nexmoe-post-footer">
          <div class="valine"></div>
<script src='https://lib.baomitu.com/valine/1.3.9/Valine.min.js'></script>
<script>
  new Valine({
      el: '.valine',
      appId: 'r5zxC0st0DDjPA9auXzMV7HY-gzGzoHsz',
      appKey: '3bqCsovpyfTPHUzTHovd3V3V'
  })
</script>

      </div>
  
</div></div><div class="nexmoe-post-right">    <div class="nexmoe-fixed">
        <div class="nexmoe-tool">

            

            
            
            <button class="mdui-fab catalog" style="overflow:unset;">
                <i class="nexmoefont icon-i-catalog"></i>
                <div class="nexmoe-toc">
                    <ol class="toc"><li class="toc-item toc-level-4"><a class="toc-link" href="#1-%E9%82%AE%E7%AE%B1"><span class="toc-number">1.</span> <span class="toc-text">1.邮箱</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#2-%E6%89%8B%E6%9C%BA%E5%8F%B7%E7%A0%81"><span class="toc-number">2.</span> <span class="toc-text">2.手机号码</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#3-%E7%94%B5%E8%AF%9D%E5%8F%B7%E7%A0%81"><span class="toc-number">3.</span> <span class="toc-text">3.电话号码</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#4-%E6%98%AF%E5%90%A6%E4%B8%BAurl%E5%9C%B0%E5%9D%80"><span class="toc-number">4.</span> <span class="toc-text">4.是否为url地址</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#5-%E6%98%AF%E5%90%A6%E5%AD%97%E7%AC%A6%E4%B8%B2"><span class="toc-number">5.</span> <span class="toc-text">5.是否字符串</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#6-%E6%98%AF%E5%90%A6%E6%95%B0%E5%AD%97"><span class="toc-number">6.</span> <span class="toc-text">6.是否数字</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#7-%E6%98%AF%E5%90%A6%E4%B8%BAboolean"><span class="toc-number">7.</span> <span class="toc-text">7.是否为boolean</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#8-%E6%98%AF%E5%90%A6%E4%B8%BA%E5%87%BD%E6%95%B0"><span class="toc-number">8.</span> <span class="toc-text">8.是否为函数</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#9-%E6%98%AF%E5%90%A6%E4%B8%BAnull"><span class="toc-number">9.</span> <span class="toc-text">9.是否为null</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#10-%E6%98%AF%E5%90%A6%E4%B8%BAundefined"><span class="toc-number">10.</span> <span class="toc-text">10.是否为undefined</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#11-%E6%98%AF%E5%90%A6%E4%B8%BA%E5%AF%B9%E8%B1%A1"><span class="toc-number">11.</span> <span class="toc-text">11.是否为对象</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#12-%E6%98%AF%E5%90%A6%E4%B8%BA%E6%95%B0%E7%BB%84"><span class="toc-number">12.</span> <span class="toc-text">12.是否为数组</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#13-%E6%98%AF%E5%90%A6%E4%B8%BA%E6%97%B6%E9%97%B4"><span class="toc-number">13.</span> <span class="toc-text">13.是否为时间</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#14-%E6%98%AF%E5%90%A6%E4%B8%BA%E6%AD%A3%E5%88%99"><span class="toc-number">14.</span> <span class="toc-text">14.是否为正则</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#15-%E6%98%AF%E5%90%A6%E4%B8%BA%E9%94%99%E8%AF%AF%E5%AF%B9%E8%B1%A1"><span class="toc-number">15.</span> <span class="toc-text">15.是否为错误对象</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#16-%E6%98%AF%E5%90%A6%E4%B8%BASymbol%E5%87%BD%E6%95%B0"><span class="toc-number">16.</span> <span class="toc-text">16.是否为Symbol函数</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#17-%E6%98%AF%E5%90%A6%E4%B8%BAPromise%E5%AF%B9%E8%B1%A1"><span class="toc-number">17.</span> <span class="toc-text">17.是否为Promise对象</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#18-%E6%98%AF%E5%90%A6%E4%B8%BASet%E5%AF%B9%E8%B1%A1"><span class="toc-number">18.</span> <span class="toc-text">18.是否为Set对象</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#19-%E6%98%AF%E5%90%A6%E6%98%AF%E5%BE%AE%E4%BF%A1%E6%B5%8F%E8%A7%88%E5%99%A8"><span class="toc-number">19.</span> <span class="toc-text">19.是否是微信浏览器</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#20-%E6%98%AF%E5%90%A6%E4%B8%BA%E7%A7%BB%E5%8A%A8%E7%AB%AF"><span class="toc-number">20.</span> <span class="toc-text">20.是否为移动端</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#21-%E6%98%AF%E5%90%A6%E6%98%AFQQ%E6%B5%8F%E8%A7%88%E5%99%A8"><span class="toc-number">21.</span> <span class="toc-text">21.是否是QQ浏览器</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#22-%E6%98%AF%E5%90%A6%E4%B8%BAios"><span class="toc-number">22.</span> <span class="toc-text">22.是否为ios</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#23-%E6%98%AF%E5%90%A6%E4%B8%BAPC%E7%AB%AF"><span class="toc-number">23.</span> <span class="toc-text">23.是否为PC端</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#24-%E5%8E%BB%E9%99%A4html%E6%A0%87%E7%AD%BE"><span class="toc-number">24.</span> <span class="toc-text">24.去除html标签</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#25-%E8%8E%B7%E5%8F%96url%E5%8F%82%E6%95%B0"><span class="toc-number">25.</span> <span class="toc-text">25.获取url参数</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#26-%E5%8A%A8%E6%80%81%E5%BC%95%E5%85%A5js"><span class="toc-number">26.</span> <span class="toc-text">26.动态引入js</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#27-%E6%A0%B9%E6%8D%AEurl%E5%9C%B0%E5%9D%80%E4%B8%8B%E8%BD%BD"><span class="toc-number">27.</span> <span class="toc-text">27.根据url地址下载</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#28-el%E6%98%AF%E5%90%A6%E5%8C%85%E5%90%AB%E6%9F%90%E4%B8%AAclass"><span class="toc-number">28.</span> <span class="toc-text">28.el是否包含某个class</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#29-el%E6%B7%BB%E5%8A%A0%E6%9F%90%E4%B8%AAclass"><span class="toc-number">29.</span> <span class="toc-text">29.el添加某个class</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#30-el%E5%8E%BB%E9%99%A4%E6%9F%90%E4%B8%AAclass"><span class="toc-number">30.</span> <span class="toc-text">30.el去除某个class</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#31-%E8%8E%B7%E5%8F%96%E6%BB%9A%E5%8A%A8%E7%9A%84%E5%9D%90%E6%A0%87"><span class="toc-number">31.</span> <span class="toc-text">31.获取滚动的坐标</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#32-%E6%BB%9A%E5%8A%A8%E5%88%B0%E9%A1%B6%E9%83%A8"><span class="toc-number">32.</span> <span class="toc-text">32.滚动到顶部</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#33-el%E6%98%AF%E5%90%A6%E5%9C%A8%E8%A7%86%E5%8F%A3%E8%8C%83%E5%9B%B4%E5%86%85"><span class="toc-number">33.</span> <span class="toc-text">33.el是否在视口范围内</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#34-%E6%B4%97%E7%89%8C%E7%AE%97%E6%B3%95%E9%9A%8F%E6%9C%BA"><span class="toc-number">34.</span> <span class="toc-text">34.洗牌算法随机</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#35-%E5%8A%AB%E6%8C%81%E7%B2%98%E8%B4%B4%E6%9D%BF"><span class="toc-number">35.</span> <span class="toc-text">35.劫持粘贴板</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#36-%E5%88%A4%E6%96%AD%E7%B1%BB%E5%9E%8B%E9%9B%86%E5%90%88"><span class="toc-number">36.</span> <span class="toc-text">36.判断类型集合</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#37-%E4%B8%A5%E6%A0%BC%E7%9A%84%E8%BA%AB%E4%BB%BD%E8%AF%81%E6%A0%A1%E9%AA%8C"><span class="toc-number">37.</span> <span class="toc-text">37.严格的身份证校验</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#38-%E9%9A%8F%E6%9C%BA%E6%95%B0%E8%8C%83%E5%9B%B4"><span class="toc-number">38.</span> <span class="toc-text">38.随机数范围</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#39-%E5%B0%86%E9%98%BF%E6%8B%89%E4%BC%AF%E6%95%B0%E5%AD%97%E7%BF%BB%E8%AF%91%E6%88%90%E4%B8%AD%E6%96%87%E7%9A%84%E5%A4%A7%E5%86%99%E6%95%B0%E5%AD%97"><span class="toc-number">39.</span> <span class="toc-text">39.将阿拉伯数字翻译成中文的大写数字</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#40-%E5%B0%86%E6%95%B0%E5%AD%97%E8%BD%AC%E6%8D%A2%E4%B8%BA%E5%A4%A7%E5%86%99%E9%87%91%E9%A2%9D"><span class="toc-number">40.</span> <span class="toc-text">40.将数字转换为大写金额</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#41-%E5%88%A4%E6%96%AD%E4%B8%80%E4%B8%AA%E5%85%83%E7%B4%A0%E6%98%AF%E5%90%A6%E5%9C%A8%E6%95%B0%E7%BB%84%E4%B8%AD"><span class="toc-number">41.</span> <span class="toc-text">41.判断一个元素是否在数组中</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#42-%E6%95%B0%E7%BB%84%E6%8E%92%E5%BA%8F-type-1%EF%BC%9A%E4%BB%8E%E5%B0%8F%E5%88%B0%E5%A4%A7-2%EF%BC%9A%E4%BB%8E%E5%A4%A7%E5%88%B0%E5%B0%8F-3%EF%BC%9A%E9%9A%8F%E6%9C%BA"><span class="toc-number">42.</span> <span class="toc-text">42.数组排序, {type} 1：从小到大 2：从大到小 3：随机</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#43-%E6%95%B0%E7%BB%84%E5%8E%BB%E9%87%8D"><span class="toc-number">43.</span> <span class="toc-text">43.数组去重</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#44-%E6%B1%82%E4%B8%A4%E4%B8%AA%E9%9B%86%E5%90%88%E7%9A%84%E5%B9%B6%E9%9B%86"><span class="toc-number">44.</span> <span class="toc-text">44.求两个集合的并集</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#45-%E6%B1%82%E4%B8%A4%E4%B8%AA%E9%9B%86%E5%90%88%E7%9A%84%E4%BA%A4%E9%9B%86"><span class="toc-number">45.</span> <span class="toc-text">45.求两个集合的交集</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#46-%E5%88%A0%E9%99%A4%E6%95%B0%E7%BB%84%E6%8C%87%E5%AE%9A%E5%85%83%E7%B4%A0"><span class="toc-number">46.</span> <span class="toc-text">46.删除数组指定元素</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#47-%E5%B0%86%E7%B1%BB%E6%95%B0%E7%BB%84%E8%BD%AC%E6%8D%A2%E4%B8%BA%E6%95%B0%E7%BB%84"><span class="toc-number">47.</span> <span class="toc-text">47.将类数组转换为数组</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#48-%E6%89%BE%E5%87%BA%E6%95%B0%E7%BB%84%E6%9C%80%E5%A4%A7%E5%80%BC"><span class="toc-number">48.</span> <span class="toc-text">48.找出数组最大值</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#49-%E6%89%BE%E5%87%BA%E6%95%B0%E7%BB%84%E6%9C%80%E5%B0%8F%E5%80%BC"><span class="toc-number">49.</span> <span class="toc-text">49.找出数组最小值</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#50-%E6%95%B0%E7%BB%84%E6%B1%82%E5%92%8C"><span class="toc-number">50.</span> <span class="toc-text">50.数组求和</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#51-%E6%95%B0%E7%BB%84%E5%B9%B3%E5%9D%87%E6%95%B0"><span class="toc-number">51.</span> <span class="toc-text">51.数组平均数</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#52-%E5%8E%BB%E9%99%A4%E7%A9%BA%E6%A0%BC-type-1-%E6%89%80%E6%9C%89%E7%A9%BA%E6%A0%BC-2-%E5%89%8D%E5%90%8E%E7%A9%BA%E6%A0%BC-3-%E5%89%8D%E7%A9%BA%E6%A0%BC-4-%E5%90%8E%E7%A9%BA%E6%A0%BC"><span class="toc-number">52.</span> <span class="toc-text">52.去除空格,type: 1-所有空格 2-前后空格 3-前空格 4-后空格</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#53-%E5%AD%97%E7%AC%A6%E8%BD%AC%E6%8D%A2-type-1-%E9%A6%96%E5%AD%97%E6%AF%8D%E5%A4%A7%E5%86%99-2%EF%BC%9A%E9%A6%96%E5%AD%97%E6%AF%8D%E5%B0%8F%E5%86%99-3%EF%BC%9A%E5%A4%A7%E5%B0%8F%E5%86%99%E8%BD%AC%E6%8D%A2-4%EF%BC%9A%E5%85%A8%E9%83%A8%E5%A4%A7%E5%86%99-5%EF%BC%9A%E5%85%A8%E9%83%A8%E5%B0%8F%E5%86%99"><span class="toc-number">53.</span> <span class="toc-text">53.字符转换,type: 1:首字母大写 2：首字母小写 3：大小写转换 4：全部大写 5：全部小写</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#54-%E6%A3%80%E6%B5%8B%E5%AF%86%E7%A0%81%E5%BC%BA%E5%BA%A6"><span class="toc-number">54.</span> <span class="toc-text">54.检测密码强度</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#55-%E5%87%BD%E6%95%B0%E8%8A%82%E6%B5%81%E5%99%A8"><span class="toc-number">55.</span> <span class="toc-text">55.函数节流器</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#56-%E5%9C%A8%E5%AD%97%E7%AC%A6%E4%B8%B2%E4%B8%AD%E6%8F%92%E5%85%A5%E6%96%B0%E5%AD%97%E7%AC%A6%E4%B8%B2"><span class="toc-number">56.</span> <span class="toc-text">56.在字符串中插入新字符串</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#57-%E5%88%A4%E6%96%AD%E4%B8%A4%E4%B8%AA%E5%AF%B9%E8%B1%A1%E6%98%AF%E5%90%A6%E9%94%AE%E5%80%BC%E7%9B%B8%E5%90%8C"><span class="toc-number">57.</span> <span class="toc-text">57.判断两个对象是否键值相同</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#58-16%E8%BF%9B%E5%88%B6%E9%A2%9C%E8%89%B2%E8%BD%ACRGBRGBA%E5%AD%97%E7%AC%A6%E4%B8%B2"><span class="toc-number">58.</span> <span class="toc-text">58.16进制颜色转RGBRGBA字符串</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#59-%E8%BF%BD%E5%8A%A0url%E5%8F%82%E6%95%B0"><span class="toc-number">59.</span> <span class="toc-text">59.追加url参数</span></a></li></ol>
                </div>
            </button>
            

            

            <a href="#nexmoe-content" class="backtop toc-link" aria-label="Back To Top" title="top"><button class="mdui-fab mdui-ripple"><i class="nexmoefont icon-caret-top"></i></button></a>
        </div>
    </div>
</div></div><div id="nexmoe-pendant"><div class="nexmoe-drawer mdui-drawer nexmoe-pd" id="drawer">
    
        
            <div class="nexmoe-pd-item">
                <div class="clock">
        <div class="memory"></div>
        <div class="memory"></div>
        <div class="memory"></div>
        <div class="memory"></div>
        <div class="memory"></div>
        <div class="memory"></div>
        <div class="memory"></div>
        <div class="memory"></div>
        <div class="memory"></div>
        <div class="memory"></div>
        <div class="memory"></div>
        <div class="memory"></div>
        <div class="memory"></div>
        <div class="memory"></div>
        <div class="memory"></div>
        <div class="memory"></div>
        <div class="memory"></div>
        <div class="memory"></div>
        <div class="memory"></div>
        <div class="memory"></div>
        <div class="memory"></div>
        <div class="memory"></div>
        <div class="memory"></div>
        <div class="memory"></div>
        <div class="memory"></div>
        <div class="memory"></div>
        <div class="memory"></div>
        <div class="memory"></div>
        <div class="memory"></div>
        <div class="memory"></div>
        <div class="memory"></div>
        <div class="memory"></div>
        <div class="memory"></div>
        <div class="memory"></div>
        <div class="memory"></div>
        <div class="memory"></div>
        <div class="memory"></div>
        <div class="memory"></div>
        <div class="memory"></div>
        <div class="memory"></div>
        <div class="memory"></div>
        <div class="memory"></div>
        <div class="memory"></div>
        <div class="memory"></div>
        <div class="memory"></div>
        <div class="memory"></div>
        <div class="memory"></div>
        <div class="memory"></div>
        <div class="memory"></div>
        <div class="memory"></div>
        <div class="memory"></div>
        <div class="memory"></div>
        <div class="memory"></div>
        <div class="memory"></div>
        <div class="memory"></div>
        <div class="memory"></div>
        <div class="memory"></div>
        <div class="memory"></div>
        <div class="memory"></div>
        <div class="memory"></div>
        <div class="needle" id="hours"></div>
        <div class="needle" id="minutes"></div>
        <div class="needle" id="seconds"></div>
        <div class="clock_logo">

        </div>

    </div>
<script>
        // ----- Variable declaration

        var data = {
                dt: new Date(),
                hours: {
                        el: document.querySelector('#hours'),
                        val: 0 },

                minutes: {
                        el: document.querySelector('#minutes'),
                        val: 0 },

                seconds: {
                        el: document.querySelector('#seconds'),
                        val: 0 },

                renderTime: 1000 };


        // ----- Clock rendering logic

        updateTime = () => {
                let hour = data.dt.getHours();
                let minute = data.dt.getMinutes();
                let second = data.dt.getSeconds();

                data.hours.el.classList.add('moving');
                data.minutes.el.classList.add('moving');
                data.seconds.el.classList.add('moving');

                data.hours.val = hour == 0 && data.hours.val == 59 * 6 * 5 ? 360 : hour * 6 * 5;
                data.minutes.val = minute == 0 && data.minutes.val == 59 * 6 ? 360 : minute * 6;
                data.seconds.val = second == 0 && data.seconds.val == 59 * 6 ? 360 : second * 6;

                data.hours.el.style.transform = `translate(-50%, -75%) rotate(${data.hours.val}deg)`;
                data.minutes.el.style.transform = `translate(-50%, -75%) rotate(${data.minutes.val}deg)`;
                data.seconds.el.style.transform = `translate(-50%, -75%) rotate(${data.seconds.val}deg)`;

                data.dt.setSeconds(second + 1);
        };

        // ----- Clock execution

        setInterval(() => {
                updateTime();
        }, data.renderTime);

        updateTime();

        // ----- Events area

        data.seconds.el.addEventListener('transitionend', () => {
                data.hours.el.classList.remove('moving');
                data.minutes.el.classList.remove('moving');
                data.seconds.el.classList.remove('moving');

                // if (data.hours.val == 360) {
                //   data.hours.el.style.transform = 'translate(-50%, -75%) rotate(0deg)';
                // }

                if (data.minutes.val == 360) {
                        data.minutes.el.style.transform = 'translate(-50%, -75%) rotate(0deg)';
                }

                if (data.seconds.val == 360) {
                        data.seconds.el.style.transform = 'translate(-50%, -75%) rotate(0deg)';
                }
        });

</script>
<style>
    .clock {
        background-color: #ffffff;
        width: 70vw;
        height: 70vw;
        max-width: 70vh;
        max-height: 70vh;
        border: solid 2.8vw var(--color-primary);
        position: relative;
        overflow: hidden;
        border-radius: 50%;
        box-sizing: border-box;
        box-shadow: 0 1.4vw 2.8vw var(--color2);
        zoom:0.2
    }

    .memory {
        position: absolute;
        top: 50%;
        left: 50%;
        transform-origin: center;
    }

    .memory:nth-child(1) {
        background-color: var(--color-primary);
        width: 2%;
        height: 8%;
        transform: translate(-50%, -50%) rotate(0deg) translateY(-520%);
    }

    .memory:nth-child(2) {
        background-color: #949494;
        width: 1%;
        height: 3%;
        transform: translate(-50%, -50%) rotate(6deg) translateY(-1461%);
    }

    .memory:nth-child(3) {
        background-color: #949494;
        width: 1%;
        height: 3%;
        transform: translate(-50%, -50%) rotate(12deg) translateY(-1461%);
    }

    .memory:nth-child(4) {
        background-color: #949494;
        width: 1%;
        height: 3%;
        transform: translate(-50%, -50%) rotate(18deg) translateY(-1461%);
    }

    .memory:nth-child(5) {
        background-color: #949494;
        width: 1%;
        height: 3%;
        transform: translate(-50%, -50%) rotate(24deg) translateY(-1461%);
    }

    .memory:nth-child(6) {
        background-color: var(--color-primary);
        width: 2%;
        height: 8%;
        transform: translate(-50%, -50%) rotate(30deg) translateY(-520%);
    }

    .memory:nth-child(7) {
        background-color: #949494;
        width: 1%;
        height: 3%;
        transform: translate(-50%, -50%) rotate(36deg) translateY(-1461%);
    }

    .memory:nth-child(8) {
        background-color: #949494;
        width: 1%;
        height: 3%;
        transform: translate(-50%, -50%) rotate(42deg) translateY(-1461%);
    }

    .memory:nth-child(9) {
        background-color: #949494;
        width: 1%;
        height: 3%;
        transform: translate(-50%, -50%) rotate(48deg) translateY(-1461%);
    }

    .memory:nth-child(10) {
        background-color: #949494;
        width: 1%;
        height: 3%;
        transform: translate(-50%, -50%) rotate(54deg) translateY(-1461%);
    }

    .memory:nth-child(11) {
        background-color: var(--color-primary);
        width: 2%;
        height: 8%;
        transform: translate(-50%, -50%) rotate(60deg) translateY(-520%);
    }

    .memory:nth-child(12) {
        background-color: #949494;
        width: 1%;
        height: 3%;
        transform: translate(-50%, -50%) rotate(66deg) translateY(-1461%);
    }

    .memory:nth-child(13) {
        background-color: #949494;
        width: 1%;
        height: 3%;
        transform: translate(-50%, -50%) rotate(72deg) translateY(-1461%);
    }

    .memory:nth-child(14) {
        background-color: #949494;
        width: 1%;
        height: 3%;
        transform: translate(-50%, -50%) rotate(78deg) translateY(-1461%);
    }

    .memory:nth-child(15) {
        background-color: #949494;
        width: 1%;
        height: 3%;
        transform: translate(-50%, -50%) rotate(84deg) translateY(-1461%);
    }

    .memory:nth-child(16) {
        background-color: var(--color-primary);
        width: 2%;
        height: 8%;
        transform: translate(-50%, -50%) rotate(90deg) translateY(-520%);
    }

    .memory:nth-child(17) {
        background-color: #949494;
        width: 1%;
        height: 3%;
        transform: translate(-50%, -50%) rotate(96deg) translateY(-1461%);
    }

    .memory:nth-child(18) {
        background-color: #949494;
        width: 1%;
        height: 3%;
        transform: translate(-50%, -50%) rotate(102deg) translateY(-1461%);
    }

    .memory:nth-child(19) {
        background-color: #949494;
        width: 1%;
        height: 3%;
        transform: translate(-50%, -50%) rotate(108deg) translateY(-1461%);
    }

    .memory:nth-child(20) {
        background-color: #949494;
        width: 1%;
        height: 3%;
        transform: translate(-50%, -50%) rotate(114deg) translateY(-1461%);
    }

    .memory:nth-child(21) {
        background-color: var(--color-primary);
        width: 2%;
        height: 8%;
        transform: translate(-50%, -50%) rotate(120deg) translateY(-520%);
    }

    .memory:nth-child(22) {
        background-color: #949494;
        width: 1%;
        height: 3%;
        transform: translate(-50%, -50%) rotate(126deg) translateY(-1461%);
    }

    .memory:nth-child(23) {
        background-color: #949494;
        width: 1%;
        height: 3%;
        transform: translate(-50%, -50%) rotate(132deg) translateY(-1461%);
    }

    .memory:nth-child(24) {
        background-color: #949494;
        width: 1%;
        height: 3%;
        transform: translate(-50%, -50%) rotate(138deg) translateY(-1461%);
    }

    .memory:nth-child(25) {
        background-color: #949494;
        width: 1%;
        height: 3%;
        transform: translate(-50%, -50%) rotate(144deg) translateY(-1461%);
    }

    .memory:nth-child(26) {
        background-color: var(--color-primary);
        width: 2%;
        height: 8%;
        transform: translate(-50%, -50%) rotate(150deg) translateY(-520%);
    }

    .memory:nth-child(27) {
        background-color: #949494;
        width: 1%;
        height: 3%;
        transform: translate(-50%, -50%) rotate(156deg) translateY(-1461%);
    }

    .memory:nth-child(28) {
        background-color: #949494;
        width: 1%;
        height: 3%;
        transform: translate(-50%, -50%) rotate(162deg) translateY(-1461%);
    }

    .memory:nth-child(29) {
        background-color: #949494;
        width: 1%;
        height: 3%;
        transform: translate(-50%, -50%) rotate(168deg) translateY(-1461%);
    }

    .memory:nth-child(30) {
        background-color: #949494;
        width: 1%;
        height: 3%;
        transform: translate(-50%, -50%) rotate(174deg) translateY(-1461%);
    }

    .memory:nth-child(31) {
        background-color: var(--color-primary);
        width: 2%;
        height: 8%;
        transform: translate(-50%, -50%) rotate(180deg) translateY(-520%);
    }

    .memory:nth-child(32) {
        background-color: #949494;
        width: 1%;
        height: 3%;
        transform: translate(-50%, -50%) rotate(186deg) translateY(-1461%);
    }

    .memory:nth-child(33) {
        background-color: #949494;
        width: 1%;
        height: 3%;
        transform: translate(-50%, -50%) rotate(192deg) translateY(-1461%);
    }

    .memory:nth-child(34) {
        background-color: #949494;
        width: 1%;
        height: 3%;
        transform: translate(-50%, -50%) rotate(198deg) translateY(-1461%);
    }

    .memory:nth-child(35) {
        background-color: #949494;
        width: 1%;
        height: 3%;
        transform: translate(-50%, -50%) rotate(204deg) translateY(-1461%);
    }

    .memory:nth-child(36) {
        background-color: var(--color-primary);
        width: 2%;
        height: 8%;
        transform: translate(-50%, -50%) rotate(210deg) translateY(-520%);
    }

    .memory:nth-child(37) {
        background-color: #949494;
        width: 1%;
        height: 3%;
        transform: translate(-50%, -50%) rotate(216deg) translateY(-1461%);
    }

    .memory:nth-child(38) {
        background-color: #949494;
        width: 1%;
        height: 3%;
        transform: translate(-50%, -50%) rotate(222deg) translateY(-1461%);
    }

    .memory:nth-child(39) {
        background-color: #949494;
        width: 1%;
        height: 3%;
        transform: translate(-50%, -50%) rotate(228deg) translateY(-1461%);
    }

    .memory:nth-child(40) {
        background-color: #949494;
        width: 1%;
        height: 3%;
        transform: translate(-50%, -50%) rotate(234deg) translateY(-1461%);
    }

    .memory:nth-child(41) {
        background-color: var(--color-primary);
        width: 2%;
        height: 8%;
        transform: translate(-50%, -50%) rotate(240deg) translateY(-520%);
    }

    .memory:nth-child(42) {
        background-color: #949494;
        width: 1%;
        height: 3%;
        transform: translate(-50%, -50%) rotate(246deg) translateY(-1461%);
    }

    .memory:nth-child(43) {
        background-color: #949494;
        width: 1%;
        height: 3%;
        transform: translate(-50%, -50%) rotate(252deg) translateY(-1461%);
    }

    .memory:nth-child(44) {
        background-color: #949494;
        width: 1%;
        height: 3%;
        transform: translate(-50%, -50%) rotate(258deg) translateY(-1461%);
    }

    .memory:nth-child(45) {
        background-color: #949494;
        width: 1%;
        height: 3%;
        transform: translate(-50%, -50%) rotate(264deg) translateY(-1461%);
    }

    .memory:nth-child(46) {
        background-color: var(--color-primary);
        width: 2%;
        height: 8%;
        transform: translate(-50%, -50%) rotate(270deg) translateY(-520%);
    }

    .memory:nth-child(47) {
        background-color: #949494;
        width: 1%;
        height: 3%;
        transform: translate(-50%, -50%) rotate(276deg) translateY(-1461%);
    }

    .memory:nth-child(48) {
        background-color: #949494;
        width: 1%;
        height: 3%;
        transform: translate(-50%, -50%) rotate(282deg) translateY(-1461%);
    }

    .memory:nth-child(49) {
        background-color: #949494;
        width: 1%;
        height: 3%;
        transform: translate(-50%, -50%) rotate(288deg) translateY(-1461%);
    }

    .memory:nth-child(50) {
        background-color: #949494;
        width: 1%;
        height: 3%;
        transform: translate(-50%, -50%) rotate(294deg) translateY(-1461%);
    }

    .memory:nth-child(51) {
        background-color: var(--color-primary);
        width: 2%;
        height: 8%;
        transform: translate(-50%, -50%) rotate(300deg) translateY(-520%);
    }

    .memory:nth-child(52) {
        background-color: #949494;
        width: 1%;
        height: 3%;
        transform: translate(-50%, -50%) rotate(306deg) translateY(-1461%);
    }

    .memory:nth-child(53) {
        background-color: #949494;
        width: 1%;
        height: 3%;
        transform: translate(-50%, -50%) rotate(312deg) translateY(-1461%);
    }

    .memory:nth-child(54) {
        background-color: #949494;
        width: 1%;
        height: 3%;
        transform: translate(-50%, -50%) rotate(318deg) translateY(-1461%);
    }

    .memory:nth-child(55) {
        background-color: #949494;
        width: 1%;
        height: 3%;
        transform: translate(-50%, -50%) rotate(324deg) translateY(-1461%);
    }

    .memory:nth-child(56) {
        background-color: var(--color-primary);
        width: 2%;
        height: 8%;
        transform: translate(-50%, -50%) rotate(330deg) translateY(-520%);
    }

    .memory:nth-child(57) {
        background-color: #949494;
        width: 1%;
        height: 3%;
        transform: translate(-50%, -50%) rotate(336deg) translateY(-1461%);
    }

    .memory:nth-child(58) {
        background-color: #949494;
        width: 1%;
        height: 3%;
        transform: translate(-50%, -50%) rotate(342deg) translateY(-1461%);
    }

    .memory:nth-child(59) {
        background-color: #949494;
        width: 1%;
        height: 3%;
        transform: translate(-50%, -50%) rotate(348deg) translateY(-1461%);
    }

    .memory:nth-child(60) {
        background-color: #949494;
        width: 1%;
        height: 3%;
        transform: translate(-50%, -50%) rotate(354deg) translateY(-1461%);
    }

    .needle {
        position: absolute;
        top: 50%;
        left: 50%;
        transform-origin: center;
    }

    .needle#hours {
        background-color: #1f1f1f;
        width: 4%;
        height: 30%;
        transform-origin: center 75%;
        transform: translate(-50%, -75%);
    }

    .needle#hours.moving {
        transition: transform 150ms ease-out;
    }

    .needle#hours:after {
        content: '';
        background-color: #1f1f1f;
        width: 4vw;
        height: 4vw;
        max-width: 4vh;
        max-height: 4vh;
        display: block;
        position: absolute;
        top: 75%;
        left: 50%;
        box-sizing: border-box;
        border-radius: 50%;
        transform: translate(-50%, -50%);
    }

    .needle#minutes {
        background-color: #1f1f1f;
        width: 2%;
        height: 45%;
        transform-origin: center 75%;
        transform: translate(-50%, -75%);
    }

    .needle#minutes.moving {
        transition: transform 150ms ease-out;
    }

    .needle#minutes:after {
        content: '';
        background-color: #1f1f1f;
        width: 4vw;
        height: 4vw;
        max-width: 4vh;
        max-height: 4vh;
        display: block;
        position: absolute;
        top: 75%;
        left: 50%;
        box-sizing: border-box;
        border-radius: 50%;
        transform: translate(-50%, -50%);
    }

    .needle#seconds {
        background-color: #cb2f2f;
        width: 1%;
        height: 50%;
        transform-origin: center 75%;
        transform: translate(-50%, -75%);
    }

    .needle#seconds.moving {
        transition: transform 150ms ease-out;
    }

    .needle#seconds:after {
        content: '';
        background-color: #cb2f2f;
        width: 2.5vw;
        height: 2.5vw;
        max-width: 2.5vh;
        max-height: 2.5vh;
        display: block;
        position: absolute;
        top: 75%;
        left: 50%;
        box-sizing: border-box;
        border-radius: 50%;
        transform: translate(-50%, -50%);
    }
    .clock_logo{
        width: 10vw;
        height: 10vw;
        max-width: 10vh;
        max-height: 10vh;
        position: absolute;
        top: 50%;
        left: 50%;
        box-sizing: border-box;
        border-radius: 50%;
        transform: translate(-50%, -50%);
        background-size: 100% 100%;
        background-repeat: no-repeat;
    }
    .clock_logo{
            width: 10vw;
            height: 10vw;
            max-width: 10vh;
            max-height: 10vh;
            position: absolute;
            top: 50%;
            left: 50%;
            box-sizing: border-box;
            border-radius: 50%;
            transform: translate(-50%, -50%);
            background-image: var(--clock-logo);
            background-size: 100% 100%;
            background-repeat: no-repeat;
    }
    @media (min-width: 100vh) {
        .clock {
            border: solid 2.8vh var(--color-primary);
            box-shadow: 0 1.4vh 2.8vh var(--color2);
        }
    }

</style>





            </div>
        
            <div class="nexmoe-pd-item">
                <div class="qweather" >
    <div id="he-plugin-standard">
        <iframe allowtransparency="true" frameborder="0" width="304" height="96" scrolling="no" src="//tianqi.2345.com/plugin/widget/index.htm?s=2&z=1&t=0&v=0&d=2&bd=0&k=000000&f=ff8040&ltf=009944&htf=cc0000&q=1&e=1&a=1&c=54511&w=300&h=96&align=center"></iframe>
    </div>
    <div class="qweather-logo">

    </div>
</div>
<style>
    .qweather{
        position: relative;
        padding-right: 5px;
    }
    .qweather #he-plugin-standard {
        border: 2px solid var(--color-primary);
        box-shadow: 0 1px 0 0 var(--color-primary), 0 1px 2px 0 var(--color-primary);
        border-radius: 8px;
        width: 300px;
        overflow: hidden;
    }
    .qweather-logo{
        position: absolute;
        right: 0;
        top: -15px;
        width: 40px;
        height: 40px;
        background-image: var(--qweather-logo);
        background-size: 100% 100%;
        background-repeat: no-repeat;
    }
</style>

            </div>
        
    
</div>
<style>
    .nexmoe-pd {
        left: auto;
        top: 40px;
        right: 0;
    }
    .nexmoe-pd-item{
       display: flex;
        justify-content: center;
        margin-bottom: 30px;
    }
    #nexmoe-pendant .mdui-drawer{
        width: 305px;
    }
    @media screen and (max-width: 1600px) {
        #nexmoe-pendant {
            display: none
        }
    }
</style>
</div><div id="nexmoe-footer"><!--!--></div><div id="nexmoe-search-space"><div class="search-container"><div class="search-header"><div class="search-input-container"><input class="search-input" type="text" placeholder="搜索" onInput="sinput();"></div><a class="search-close" onclick="sclose();">×</a></div><div class="search-body"></div></div></div><div></div><!-- hexo injector body_end start -->
<script src="https://cdn.jsdelivr.net/npm/hexo-shiki-plugin@latest/lib/codeblock.js"></script>

  <script>
  const CODE_CONFIG = {
    beautify: true,
    highlightCopy: true,
    highlightLang: true,
    highlightHeightLimit: null,
    isHighlightShrink: false,
    copy: {
      success: 'Copy Success',
      error: 'Copy Error',
      noSupport: 'Browser Not Support',
    }
  };
  console.log(
    `%c hexo-shiki-plugin %c v1.0.27 %c https://github.com/nova1751/hexo-shiki-plugin`,
    "color: #fff; background: #5f5f5f",
    "color: #fff; background: #80c8f8",
    ""
  );
  </script>
  <!-- hexo injector body_end end --><script src="/live2dw/lib/L2Dwidget.min.js?094cbace49a39548bed64abff5988b05"></script><script>L2Dwidget.init({"model":{"jsonPath":"/live2dw/assets/xiaomai.model.json"},"display":{"position":"left","width":200,"height":500},"mobile":{"show":false},"react":{"opacity":0.9},"log":false,"pluginJsPath":"lib/","pluginModelPath":"assets/","pluginRootPath":"live2dw/","tagMode":false});</script></body></html>